nquery ( goal-def/defs n/f -- bindings-array/success? )


Vocabulary
logic

Inputs
goal-def/defsa goal def or an array of goal defs
n/fthe 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


:: 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 ;