]> gitweb.factorcode.org Git - factor.git/blob - basis/combinators/short-circuit/short-circuit.factor
7b6c1d126da8fadc4c1fad0cb9d48b2599dc64eb
[factor.git] / basis / combinators / short-circuit / short-circuit.factor
1
2 USING: kernel combinators quotations arrays sequences assocs
3        locals generalizations macros fry ;
4
5 IN: combinators.short-circuit
6
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
9 :: n&&-rewrite ( quots N -- quot )
10    quots
11      [ '[ drop N ndup @ dup not ] [ drop N ndrop f ] 2array ]
12    map
13    [ t ] [ N nnip ] 2array suffix
14    '[ f _ cond ] ;
15
16 MACRO: 0&& ( quots -- quot ) 0 n&&-rewrite ;
17 MACRO: 1&& ( quots -- quot ) 1 n&&-rewrite ;
18 MACRO: 2&& ( quots -- quot ) 2 n&&-rewrite ;
19 MACRO: 3&& ( quots -- quot ) 3 n&&-rewrite ;
20
21 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22
23 :: n||-rewrite ( quots N -- quot )
24    quots
25      [ '[ drop N ndup @ dup ] [ N nnip ] 2array ]
26    map
27    [ drop N ndrop t ] [ f ] 2array suffix
28    '[ f _ cond ] ;
29
30 MACRO: 0|| ( quots -- quot ) 0 n||-rewrite ;
31 MACRO: 1|| ( quots -- quot ) 1 n||-rewrite ;
32 MACRO: 2|| ( quots -- quot ) 2 n||-rewrite ;
33 MACRO: 3|| ( quots -- quot ) 3 n||-rewrite ;
34
35 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!