]> gitweb.factorcode.org Git - factor.git/blob - basis/combinators/smart/smart.factor
Merge branch 'master' into experimental
[factor.git] / basis / combinators / smart / smart.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors fry generalizations kernel macros math.order
4 stack-checker math ;
5 IN: combinators.smart
6
7 MACRO: output>sequence ( quot exemplar -- newquot )
8     [ dup infer out>> ] dip
9     '[ @ _ _ nsequence ] ;
10
11 : output>array ( quot -- newquot )
12     { } output>sequence ; inline
13
14 MACRO: input<sequence ( quot -- newquot )
15     [ infer in>> ] keep
16     '[ _ firstn @ ] ;
17
18 MACRO: reduce-outputs ( quot operation -- newquot )
19     [ dup infer out>> 1 [-] ] dip n*quot compose ;
20
21 : sum-outputs ( quot -- n )
22     [ + ] reduce-outputs ; inline
23
24 MACRO: append-outputs-as ( quot exemplar -- newquot )
25     [ dup infer out>> ] dip '[ @ _ _ nappend-as ] ;
26
27 : append-outputs ( quot -- seq )
28     { } append-outputs-as ; inline