]> gitweb.factorcode.org Git - factor.git/blob - basis/combinators/smart/smart.factor
alien.destructors: ignore any output values from disposal word
[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: drop-outputs ( quot -- quot' )
8     dup infer out>> '[ @ _ ndrop ] ;
9
10 MACRO: output>sequence ( quot exemplar -- newquot )
11     [ dup infer out>> ] dip
12     '[ @ _ _ nsequence ] ;
13
14 : output>array ( quot -- newquot )
15     { } output>sequence ; inline
16
17 MACRO: input<sequence ( quot -- newquot )
18     [ infer in>> ] keep
19     '[ _ firstn @ ] ;
20
21 MACRO: reduce-outputs ( quot operation -- newquot )
22     [ dup infer out>> 1 [-] ] dip n*quot compose ;
23
24 : sum-outputs ( quot -- n )
25     [ + ] reduce-outputs ; inline
26
27 MACRO: map-reduce-outputs ( quot mapper reducer -- newquot )
28     [ dup infer out>> ] 2dip
29     [ swap '[ _ _ napply ] ]
30     [ [ 1 [-] ] dip n*quot ] bi-curry* bi
31     '[ @ @ @ ] ;
32
33 MACRO: append-outputs-as ( quot exemplar -- newquot )
34     [ dup infer out>> ] dip '[ @ _ _ nappend-as ] ;
35
36 : append-outputs ( quot -- seq )
37     { } append-outputs-as ; inline