From 93187f356b5905c7a5c42427100e71e1f3601237 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 16 Jan 2008 10:19:50 -1000 Subject: [PATCH] add map-index, each-index, 2quot-with, or?, and? --- extra/combinators/lib/lib.factor | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/extra/combinators/lib/lib.factor b/extra/combinators/lib/lib.factor index 9356d6c9b5..aae4c5d9ab 100755 --- a/extra/combinators/lib/lib.factor +++ b/extra/combinators/lib/lib.factor @@ -191,3 +191,23 @@ MACRO: construct-slots ( assoc tuple-class -- tuple ) : either ( object first second -- ? ) >r keep swap [ r> drop ] [ r> call ] ?if ; inline + +: 2quot-with ( obj seq quot1 quot2 -- seq quot1 quot2 ) + >r pick >r with r> r> swapd with ; + +: or? ( obj quot1 quot2 -- ? ) + >r keep r> rot [ 2nip ] [ call ] if* ; inline + +: and? ( obj quot1 quot2 -- ? ) + >r keep r> rot [ call ] [ 2drop f ] if ; inline + +: prepare-index ( seq quot -- seq n quot ) + >r dup length r> ; inline + +: each-index ( seq quot -- ) + #! quot: ( elt index -- ) + prepare-index 2each ; inline + +: map-index ( seq quot -- ) + #! quot: ( elt index -- obj ) + prepare-index 2map ; inline