factor/basis/combinators/short-circuit/short-circuit.factor

27 lines
835 B
Factor
Raw Normal View History

USING: kernel combinators quotations arrays sequences assocs
2008-11-21 05:00:28 -05:00
locals generalizations macros fry ;
2008-06-24 09:35:06 -04:00
IN: combinators.short-circuit
2008-11-21 05:00:28 -05:00
MACRO:: n&& ( quots n -- quot )
2008-11-21 05:36:18 -05:00
[ f ]
quots [| q | { [ drop n ndup q call dup not ] [ drop n ndrop f ] } ] map
[ n nnip ] suffix 1array
[ cond ] 3append ;
2008-11-21 05:00:28 -05:00
MACRO: 0&& ( quots -- quot ) '[ _ 0 n&& ] ;
MACRO: 1&& ( quots -- quot ) '[ _ 1 n&& ] ;
MACRO: 2&& ( quots -- quot ) '[ _ 2 n&& ] ;
MACRO: 3&& ( quots -- quot ) '[ _ 3 n&& ] ;
MACRO:: n|| ( quots n -- quot )
2008-11-21 05:36:18 -05:00
[ f ]
quots
[| q | { [ drop n ndup q call dup ] [ n nnip ] } ] map
{ [ drop n ndrop t ] [ f ] } suffix 1array
[ cond ] 3append ;
2008-11-21 05:00:28 -05:00
MACRO: 0|| ( quots -- quot ) '[ _ 0 n|| ] ;
MACRO: 1|| ( quots -- quot ) '[ _ 1 n|| ] ;
MACRO: 2|| ( quots -- quot ) '[ _ 2 n|| ] ;
MACRO: 3|| ( quots -- quot ) '[ _ 3 n|| ] ;