}
} ;
+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:"
"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"
[ { 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
: 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