Handbook
Glossary
nquery ( goal-def/defs n/f -- bindings-array/success? )
Vocabulary
logic
Inputs
goal-def/defs
a goal def or an array of goal defs
n/f
the highest number of responses
Outputs
bindings-array/success?
anser
Word description
The version of
query
that limits the number of responses. Specify a number greater than or equal to 1. If
f
is given instead of a number as
n/f
, there is no limit to the number of answers. That is, the behavior is the same as
query
.
See also
query
Definition
USING:
accessors
arrays
assocs
combinators.short-circuit
continuations
formatting
kernel
logic.private
math
namespaces
sequences
;
IN:
logic
::
nquery
( goal-def/defs n/f -- bindings-array/success? )
*trace?*
get-global
:>
trace? 0
:>
n!
f
:>
success?!
V{
}
clone
:>
bindings
<env>
:>
env goal-def/defs
replace-'__'
normalize
[
def>goal
]
map
env
f
<cut>
<resolver>
:>
resolver
[
[
resolver
next
dup
[
resolver
env>>
table>>
keys
[
get
NORMAL-LOGIC-VAR?
]
filter
[
dup
env
at
]
H{
}
map>assoc
trace?
get-global
[
dup
[
"%u: %u\n"
printf
]
assoc-each
]
when
bindings
push
t
success?! n/f
[
n 1
+
n! n n/f
>=
[
return
]
when
]
when
]
when
]
loop
]
with-return
bindings
dup
{
[
empty?
]
[
first
keys
empty?
]
}
1||
[
drop
success?
]
[
>array
]
if
;