]> gitweb.factorcode.org Git - factor.git/blob - core/combinators/short-circuit/short-circuit.factor
core: update using lists
[factor.git] / core / combinators / short-circuit / short-circuit.factor
1 USING: arrays combinators generalizations kernel math sequences ;
2 IN: combinators.short-circuit
3
4 <PRIVATE
5
6 MACRO: keeping ( n quot -- quot' )
7     swap dup 1 + '[ _ _ nkeep _ nrot ] ;
8
9 PRIVATE>
10
11 MACRO: n&& ( quots n -- quot )
12     [
13         [ [ f ] ] 2dip swap [
14             [ '[ drop _ _ keeping dup not ] ]
15             [ drop '[ drop _ ndrop f ] ]
16             2bi 2array
17         ] with map
18     ] [ '[ _ nnip ] suffix 1array ] bi
19     [ cond ] 3append ;
20
21 : 0&& ( quots -- ? ) 0 n&& ;
22 : 1&& ( obj quots -- ? ) 1 n&& ;
23 : 2&& ( obj1 obj2 quots -- ? ) 2 n&& ;
24 : 3&& ( obj1 obj2 obj3 quots -- ? ) 3 n&& ;
25
26 MACRO: n|| ( quots n -- quot )
27     [
28         [ [ f ] ] 2dip swap [
29             [ '[ drop _ _ keeping dup ] ]
30             [ drop '[ _ nnip ] ]
31             2bi 2array
32         ] with map
33     ] [ '[ drop _ ndrop t ] [ f ] 2array suffix 1array ] bi
34     [ cond ] 3append ;
35
36 : 0|| ( quots -- ? ) 0 n|| ;
37 : 1|| ( obj quots -- ? ) 1 n|| ;
38 : 2|| ( obj1 obj2 quots -- ? ) 2 n|| ;
39 : 3|| ( obj1 obj2 obj3 quots -- ? ) 3 n|| ;