Merge branch 'master' of git://github.com/littledan/Factor

db4
Slava Pestov 2010-02-09 14:35:30 +13:00
commit 5810987f13
2 changed files with 28 additions and 5 deletions

View File

@ -1,4 +1,4 @@
USING: kernel math tools.test combinators.short-circuit ;
USING: kernel math tools.test combinators.short-circuit accessors ;
IN: combinators.short-circuit.tests
[ 3 ] [ { [ 1 ] [ 2 ] [ 3 ] } 0&& ] unit-test
@ -22,4 +22,19 @@ IN: combinators.short-circuit.tests
: compiled-|| ( a b -- ? ) { [ + odd? ] [ + 100 > ] [ + ] } 2|| ;
[ 30 ] [ 10 20 compiled-|| ] unit-test
[ 2 ] [ 1 1 compiled-|| ] unit-test
[ 2 ] [ 1 1 compiled-|| ] unit-test
! && and || should be row-polymorphic both when compiled and when interpreted
: row-&& ( -- ? )
f t { [ drop dup ] } 1&& nip ;
[ f ] [ row-&& ] unit-test
[ f ] [ \ row-&& def>> call ] unit-test
: row-|| ( -- ? )
f t { [ drop dup ] } 1|| nip ;
[ f ] [ row-|| ] unit-test
[ f ] [ \ row-|| def>> call ] unit-test

View File

@ -1,11 +1,19 @@
USING: kernel combinators quotations arrays sequences assocs
generalizations macros fry ;
generalizations macros fry math ;
IN: combinators.short-circuit
<PRIVATE
MACRO: keeping ( n quot -- quot' )
swap dup 1 +
'[ _ _ nkeep _ nrot ] ;
PRIVATE>
MACRO: n&& ( quots n -- quot )
[
[ [ f ] ] 2dip swap [
[ '[ drop _ ndup @ dup not ] ]
[ '[ drop _ _ keeping dup not ] ]
[ drop '[ drop _ ndrop f ] ]
2bi 2array
] with map
@ -27,7 +35,7 @@ PRIVATE>
MACRO: n|| ( quots n -- quot )
[
[ [ f ] ] 2dip swap [
[ '[ drop _ ndup @ dup ] ]
[ '[ drop _ _ keeping dup ] ]
[ drop '[ _ nnip ] ]
2bi 2array
] with map