diff --git a/basis/combinators/short-circuit/short-circuit-tests.factor b/basis/combinators/short-circuit/short-circuit-tests.factor index b2bcb2a60f..3495555062 100644 --- a/basis/combinators/short-circuit/short-circuit-tests.factor +++ b/basis/combinators/short-circuit/short-circuit-tests.factor @@ -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 \ No newline at end of file +[ 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 + diff --git a/basis/combinators/short-circuit/short-circuit.factor b/basis/combinators/short-circuit/short-circuit.factor index dabbe07afb..284e2a60d4 100644 --- a/basis/combinators/short-circuit/short-circuit.factor +++ b/basis/combinators/short-circuit/short-circuit.factor @@ -1,11 +1,19 @@ USING: kernel combinators quotations arrays sequences assocs -generalizations macros fry ; +generalizations macros fry math ; IN: combinators.short-circuit + + 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