From 61aaa4f0dea74351644ef91e4ffaa02e9c4a9d51 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 3 Dec 2007 23:54:59 -0600 Subject: [PATCH] Add nfirst to combinators.lib and add seq>stack --- extra/combinators/lib/lib-tests.factor | 2 ++ extra/combinators/lib/lib.factor | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/extra/combinators/lib/lib-tests.factor b/extra/combinators/lib/lib-tests.factor index 43385b911d..0d76e6f50d 100644 --- a/extra/combinators/lib/lib-tests.factor +++ b/extra/combinators/lib/lib-tests.factor @@ -58,3 +58,5 @@ IN: temporary [ dup array? ] [ dup vector? ] [ dup float? ] } || nip ] unit-test + +[ 1 2 3 4 ] [ { 1 2 3 4 } 4 nfirst ] unit-test diff --git a/extra/combinators/lib/lib.factor b/extra/combinators/lib/lib.factor index 3f49da7cb3..fe11fd1338 100644 --- a/extra/combinators/lib/lib.factor +++ b/extra/combinators/lib/lib.factor @@ -67,6 +67,12 @@ MACRO: napply ( n -- ) : map-with2 ( obj obj list quot -- newseq ) 2 map-withn ; inline +MACRO: nfirst ( n -- ) + [ [ swap nth ] curry [ keep ] curry ] map concat [ drop ] compose ; + +: seq>stack ( seq -- ) + dup length nfirst ; inline + ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! : sigma ( seq quot -- n ) [ rot slip + ] curry 0 swap reduce ;