-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
: 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
+
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
MACRO: n|| ( quots n -- quot )
[
[ [ f ] ] 2dip swap [
- [ '[ drop _ ndup @ dup ] ]
+ [ '[ drop _ _ keeping dup ] ]
[ drop '[ _ nnip ] ]
2bi 2array
] with map