combinators.extras: adding swap-when.

db4
John Benediktsson 2014-12-03 12:03:04 -08:00
parent 6fd908da40
commit 1e1646a691
2 changed files with 6 additions and 0 deletions

View File

@ -29,3 +29,6 @@ IN: combinators.extras.tests
{ 2 5 } [ 1 2 3 4 5 6 [ - - ] 3bi@ ] unit-test { 2 5 } [ 1 2 3 4 5 6 [ - - ] 3bi@ ] unit-test
{ 3 1 } [ 1 2 [ + ] keepd ] unit-test { 3 1 } [ 1 2 [ + ] keepd ] unit-test
[ "1" "123" ] [ "1" "123" [ length ] [ > ] swap-when ] unit-test
[ "123" "1" ] [ "1" "123" [ length ] [ < ] swap-when ] unit-test

View File

@ -54,3 +54,6 @@ MACRO: smart-plox ( true -- )
_ nano-count { 0 } 2dup first-unsafe _ + >= _ nano-count { 0 } 2dup first-unsafe _ + >=
[ 0 swap set-nth-unsafe call ] [ 3drop ] if [ 0 swap set-nth-unsafe call ] [ 3drop ] if
] ; inline ] ; inline
: swap-when ( x y quot: ( x -- n ) quot: ( n n -- ? ) -- x' y' )
'[ _ _ 2dup _ bi@ @ [ swap ] when ] call ; inline