1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel quotations math sequences
10 { "newquot" quotation }
12 { $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." }
15 "USING: combinators.smart math prettyprint ;"
16 "{ 1 2 3 } [ + + ] input<sequence ."
24 { "newquot" quotation }
26 { $description "Infers the number or outputs from the quotation and constructs an array from those outputs." }
29 <" USING: combinators combinators.smart math prettyprint ;
31 { [ 1- ] [ 1+ ] [ sq ] } cleave
39 { "quot" quotation } { "exemplar" "an exemplar" }
40 { "newquot" quotation }
42 { $description "Infers the number of outputs from the quotation and constructs a new sequence from those objects of the same type as the exemplar." }
45 "USING: combinators.smart kernel math prettyprint ;"
46 "4 [ [ 1 + ] [ 2 + ] [ 3 + ] tri ] V{ } output>sequence ."
53 { "quot" quotation } { "operation" quotation }
54 { "newquot" quotation }
56 { $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." }
59 "USING: combinators.smart kernel math prettyprint ;"
60 "3 [ [ 4 * ] [ 4 / ] [ 4 - ] tri ] [ * ] reduce-output ."
70 { $description "Infers the number of outputs from " { $snippet "quot" } " and returns their sum." }
73 "USING: combinators.smart kernel math prettyprint ;"
74 "10 [ [ 1- ] [ 1+ ] bi ] sum-outputs ."
79 ARTICLE: "combinators.smart" "Smart combinators"
80 "The " { $vocab-link "combinators.smart" } " vocabulary implements " { $emphasis "smart combinators" } ". A smart combinator is one whose behavior depends on the static stack effect of an input quotation." $nl
81 "Smart inputs from a sequence:"
82 { $subsection input<sequence }
83 "Smart outputs to a sequence:"
84 { $subsection output>sequence }
85 { $subsection output>array }
86 "Reducing the output of a quotation:"
87 { $subsection reduce-output }
88 "Summing the output of a quotation:"
89 { $subsection sum-outputs } ;
91 ABOUT: "combinators.smart"