2009-01-08 19:56:49 -05:00
|
|
|
! Copyright (C) 2009 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors fry generalizations kernel macros math.order
|
|
|
|
stack-checker math ;
|
|
|
|
IN: combinators.smart
|
|
|
|
|
|
|
|
MACRO: output>sequence ( quot exemplar -- newquot )
|
|
|
|
[ dup infer out>> ] dip
|
|
|
|
'[ @ _ _ nsequence ] ;
|
|
|
|
|
|
|
|
: output>array ( quot -- newquot )
|
|
|
|
{ } output>sequence ; inline
|
|
|
|
|
|
|
|
MACRO: input<sequence ( quot -- newquot )
|
|
|
|
[ infer in>> ] keep
|
|
|
|
'[ _ firstn @ ] ;
|
|
|
|
|
2009-01-09 16:39:47 -05:00
|
|
|
MACRO: reduce-outputs ( quot operation -- newquot )
|
2009-01-08 19:56:49 -05:00
|
|
|
[ dup infer out>> 1 [-] ] dip n*quot compose ;
|
|
|
|
|
|
|
|
: sum-outputs ( quot -- n )
|
2009-01-09 16:39:47 -05:00
|
|
|
[ + ] reduce-outputs ; inline
|
2009-01-18 22:18:52 -05:00
|
|
|
|
2009-02-12 03:19:41 -05:00
|
|
|
MACRO: map-reduce-outputs ( quot mapper reducer -- newquot )
|
|
|
|
[ dup infer out>> ] 2dip
|
|
|
|
[ swap '[ _ _ napply ] ]
|
|
|
|
[ [ 1 [-] ] dip n*quot ] bi-curry* bi
|
|
|
|
'[ @ @ @ ] ;
|
|
|
|
|
2009-01-18 22:18:52 -05:00
|
|
|
MACRO: append-outputs-as ( quot exemplar -- newquot )
|
|
|
|
[ dup infer out>> ] dip '[ @ _ _ nappend-as ] ;
|
|
|
|
|
|
|
|
: append-outputs ( quot -- seq )
|
|
|
|
{ } append-outputs-as ; inline
|