! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: classes.tuple help.markup help.syntax kernel math
-quotations sequences stack-checker ;
+quotations sequences stack-checker arrays ;
IN: combinators.smart
HELP: input<sequence
{ $values
- { "quot" quotation }
- { "newquot" quotation }
+ { "seq" sequence }
+ { "quot" quotation }
}
{ $description "Infers the number of inputs, " { $snippet "n" } ", to " { $snippet "quot" } " and calls the " { $snippet "quot" } " with the first " { $snippet "n" } " values from a sequence." }
{ $examples
HELP: output>array
{ $values
- { "quot" quotation }
- { "newquot" quotation }
+ { "quot" quotation }
+ { "array" array }
}
{ $description "Infers the number of outputs from the quotation and constructs an array from those outputs." }
{ $examples
HELP: output>sequence
{ $values
- { "quot" quotation } { "exemplar" "an exemplar" }
- { "newquot" quotation }
+ { "quot" quotation } { "exemplar" "an exemplar" }
+ { "seq" sequence }
}
{ $description "Infers the number of outputs from the quotation and constructs a new sequence from those objects of the same type as the exemplar." }
{ $examples
HELP: reduce-outputs
{ $values
- { "quot" quotation } { "operation" quotation }
- { "newquot" quotation }
+ { "quot" quotation } { "operation" quotation }
}
{ $description "Infers the number of outputs from " { $snippet "quot" } " and reduces them using " { $snippet "operation" } ". The identity for the " { $link reduce } " operation is the first output." }
{ $examples
HELP: sum-outputs
{ $values
- { "quot" quotation }
- { "n" integer }
+ { "quot" quotation }
+ { "n" integer }
}
{ $description "Infers the number of outputs from " { $snippet "quot" } " and returns their sum." }
{ $examples
HELP: append-outputs
{ $values
- { "quot" quotation }
- { "seq" sequence }
+ { "quot" quotation }
+ { "seq" sequence }
}
{ $description "Infers the number of outputs from " { $snippet "quot" } " and returns a sequence of the outputs appended." }
{ $examples
HELP: append-outputs-as
{ $values
- { "quot" quotation } { "exemplar" sequence }
- { "seq" sequence }
+ { "quot" quotation } { "exemplar" sequence }
+ { "seq" sequence }
}
{ $description "Infers the number of outputs from " { $snippet "quot" } " and returns a sequence of type " { $snippet "exemplar" } " of the outputs appended." }
{ $examples
HELP: dropping
{ $values
{ "quot" quotation }
- { "quot" quotation }
+ { "quot'" quotation }
}
{ $description "Outputs a quotation that, when called, will have the effect of dropping the number of inputs to the original quotation." }
{ $examples
HELP: input<sequence-unsafe
{ $values
- { "quot" quotation }
+ { "seq" sequence }
{ "quot" quotation }
}
{ $description "An unsafe version of " { $link input<sequence-unsafe } "." } ;
HELP: map-reduce-outputs
{ $values
{ "quot" quotation } { "mapper" quotation } { "reducer" quotation }
- { "quot" quotation }
}
{ $description "Infers the number of outputs from " { $snippet "quot" } " and, treating those outputs as a sequence, calls " { $link map-reduce } " on them." }
{ $examples
HELP: nullary
{ $values
{ "quot" quotation }
- { "quot" quotation }
}
{ $description "Infers the number of inputs to a quotation and drops them from the stack." }
{ $examples
HELP: preserving
{ $values
{ "quot" quotation }
- { "quot" quotation }
}
{ $description "Calls a quotation and leaves any consumed inputs on the stack beneath the quotation's outputs." }
{ $examples
HELP: smart-apply
{ $values
{ "quot" quotation } { "n" integer }
- { "quot" quotation }
}
{ $description "Applies a quotation to the datastack " { $snippet "n" } " times, starting lower on the stack and working up in increments of the number of inferred inputs to the quotation." }
{ $examples
HELP: smart-if
{ $values
{ "pred" quotation } { "true" quotation } { "false" quotation }
- { "quot" quotation }
}
{ $description "A version of " { $link if } " that takes three quotations, where the first quotation is a predicate that preserves any inputs it consumes." } ;
HELP: smart-if*
{ $values
{ "pred" quotation } { "true" quotation } { "false" quotation }
- { "quot" quotation }
}
{ $description "A version of " { $link if } " that takes three quotations, where the first quotation is a predicate that preserves any inputs it consumes, the second is the " { $snippet "true" } " branch, and the third is the " { $snippet "false" } " branch. If the " { $snippet "true" } " branch is taken, the values are left on the stack and the quotation is called. If the " { $snippet "false" } " branch is taken, the number of inputs inferred from predicate quotation is dropped and the quotation is called." } ;
HELP: smart-unless
{ $values
{ "pred" quotation } { "false" quotation }
- { "quot" quotation }
}
{ $description "A version of " { $link unless } " that takes two quotations, where the first quotation is a predicate that preserves any inputs it consumes and the second is the " { $snippet "false" } " branch." } ;
HELP: smart-unless*
{ $values
{ "pred" quotation } { "false" quotation }
- { "quot" quotation }
}
{ $description "A version of " { $link unless } " that takes two quotations, where the first quotation is a predicate that preserves any inputs it consumes and the second is the " { $snippet "false" } " branch. If the " { $snippet "true" } " branch is taken, the values are left on the stack. If the " { $snippet "false" } " branch is taken, the number of inputs inferred from predicate quotation is dropped and the quotation is called." } ;
HELP: smart-when
{ $values
{ "pred" quotation } { "true" quotation }
- { "quot" quotation }
}
{ $description "A version of " { $link when } " that takes two quotations, where the first quotation is a predicate that preserves any inputs it consumes and the second is the " { $snippet "true" } " branch." } ;
HELP: smart-when*
{ $values
{ "pred" quotation } { "true" quotation }
- { "quot" quotation }
}
{ $description "A version of " { $link when } " that takes two quotations, where the first quotation is a predicate that preserves any inputs it consumes and the second is the " { $snippet "true" } " branch. If the " { $snippet "true" } " branch is taken, the values are left on the stack and the quotation is called. If the " { $snippet "false" } " branch is taken, the number of inputs inferred from predicate quotation is dropped." } ;