]> gitweb.factorcode.org Git - factor.git/commitdiff
Add append-outputs and append-outputs-as, docs, tests
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 19 Jan 2009 03:18:52 +0000 (21:18 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 19 Jan 2009 03:18:52 +0000 (21:18 -0600)
basis/combinators/smart/smart-docs.factor
basis/combinators/smart/smart-tests.factor
basis/combinators/smart/smart.factor

index 3df709c9fa5d03f85f12a0d72e42c5334f53bda7..75f83c1a5576ac46185c98bb069d7e96e817c20b 100644 (file)
@@ -76,6 +76,37 @@ HELP: sum-outputs
     }
 } ;
 
+HELP: append-outputs
+{ $values
+     { "quot" quotation }
+     { "seq" sequence }
+}
+{ $description "Infers the number of outputs from " { $snippet "quot" } " and returns a sequence of the outputs appended." }
+{ $examples
+    { $example
+        "USING: combinators.smart prettyprint ;"
+        "[ { 1 2 } { \"A\" \"b\" } ] append-outputs ."
+        "{ 1 2 \"A\" \"b\" }"
+    }
+} ;
+
+HELP: append-outputs-as
+{ $values
+     { "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
+    { $example
+        "USING: combinators.smart prettyprint ;"
+        "[ { 1 2 } { \"A\" \"b\" } ] V{ } append-outputs-as ."
+        "V{ 1 2 \"A\" \"b\" }"
+    }
+} ;
+
+{ append-outputs append-outputs-as } related-words
+
+
 ARTICLE: "combinators.smart" "Smart combinators"
 "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
 "Smart inputs from a sequence:"
@@ -86,6 +117,9 @@ ARTICLE: "combinators.smart" "Smart combinators"
 "Reducing the output of a quotation:"
 { $subsection reduce-outputs }
 "Summing the output of a quotation:"
-{ $subsection sum-outputs } ;
+{ $subsection sum-outputs }
+"Appending the results of a quotation:"
+{ $subsection append-outputs }
+{ $subsection append-outputs-as } ;
 
 ABOUT: "combinators.smart"
index 54c53477dbc90c19b631da12495ffd1b8488d506..370dc26960f674738dda78f9e3c05e770ccad69d 100644 (file)
@@ -12,10 +12,28 @@ IN: combinators.smart.tests
 [ { 9 11 } [ + ] input<sequence ] must-infer
 [ 20 ] [ { 9 11 } [ + ] input<sequence ] unit-test
 
-
-
 [ 6 ] [ [ 1 2 3 ] [ + ] reduce-outputs ] unit-test
 
 [ [ 1 2 3 ] [ + ] reduce-outputs ] must-infer
 
 [ 6 ] [ [ 1 2 3 ] sum-outputs ] unit-test
+
+[ "ab" ]
+[
+    [ "a" "b" ] "" append-outputs-as
+] unit-test
+
+[ "" ]
+[
+    [ ] "" append-outputs-as
+] unit-test
+
+[ { } ]
+[
+    [ ] append-outputs
+] unit-test
+
+[ B{ 1 2 3 } ]
+[
+    [ { 1 } { 2 } { 3 } ] B{ } append-outputs-as
+] unit-test
index 7a68cb5c1c0bb82bca831d78ec74877f26d86fe7..e93d84e394a0edb9f6527a75da2d198ab4cfc426 100644 (file)
@@ -20,3 +20,9 @@ MACRO: reduce-outputs ( quot operation -- newquot )
 
 : sum-outputs ( quot -- n )
     [ + ] reduce-outputs ; inline
+
+MACRO: append-outputs-as ( quot exemplar -- newquot )
+    [ dup infer out>> ] dip '[ @ _ _ nappend-as ] ;
+
+: append-outputs ( quot -- seq )
+    { } append-outputs-as ; inline