Clean up combinators.short-circuit
parent
0b6916158d
commit
23550ebe16
|
@ -1,35 +1,30 @@
|
||||||
|
|
||||||
USING: kernel combinators quotations arrays sequences assocs
|
USING: kernel combinators quotations arrays sequences assocs
|
||||||
locals generalizations macros fry ;
|
locals generalizations macros fry ;
|
||||||
|
|
||||||
IN: combinators.short-circuit
|
IN: combinators.short-circuit
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
MACRO:: n&& ( quots n -- quot )
|
||||||
|
[let | pairs [
|
||||||
|
quots [| q | { [ drop n ndup q dup not ] [ drop n ndrop f ] } ] map
|
||||||
|
{ [ t ] [ n nnip ] } suffix
|
||||||
|
] |
|
||||||
|
[ f pairs cond ]
|
||||||
|
] ;
|
||||||
|
|
||||||
:: n&&-rewrite ( quots N -- quot )
|
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 )
|
||||||
|
[let | pairs [
|
||||||
quots
|
quots
|
||||||
[ '[ drop N ndup @ dup not ] [ drop N ndrop f ] 2array ]
|
[| q | { [ drop n ndup q dup ] [ n nnip ] } ] map
|
||||||
map
|
{ [ drop n ndrop t ] [ f ] } suffix
|
||||||
[ t ] [ N nnip ] 2array suffix
|
] |
|
||||||
'[ f _ cond ] ;
|
[ f pairs cond ]
|
||||||
|
] ;
|
||||||
|
|
||||||
MACRO: 0&& ( quots -- quot ) 0 n&&-rewrite ;
|
MACRO: 0|| ( quots -- quot ) '[ _ 0 n|| ] ;
|
||||||
MACRO: 1&& ( quots -- quot ) 1 n&&-rewrite ;
|
MACRO: 1|| ( quots -- quot ) '[ _ 1 n|| ] ;
|
||||||
MACRO: 2&& ( quots -- quot ) 2 n&&-rewrite ;
|
MACRO: 2|| ( quots -- quot ) '[ _ 2 n|| ] ;
|
||||||
MACRO: 3&& ( quots -- quot ) 3 n&&-rewrite ;
|
MACRO: 3|| ( quots -- quot ) '[ _ 3 n|| ] ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
:: n||-rewrite ( quots N -- quot )
|
|
||||||
quots
|
|
||||||
[ '[ drop N ndup @ dup ] [ N nnip ] 2array ]
|
|
||||||
map
|
|
||||||
[ drop N ndrop t ] [ f ] 2array suffix
|
|
||||||
'[ f _ cond ] ;
|
|
||||||
|
|
||||||
MACRO: 0|| ( quots -- quot ) 0 n||-rewrite ;
|
|
||||||
MACRO: 1|| ( quots -- quot ) 1 n||-rewrite ;
|
|
||||||
MACRO: 2|| ( quots -- quot ) 2 n||-rewrite ;
|
|
||||||
MACRO: 3|| ( quots -- quot ) 3 n||-rewrite ;
|
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
Loading…
Reference in New Issue