From 25fa0248987861d33a00c0f1bbdc6bc9fc0a38ef Mon Sep 17 00:00:00 2001 From: James Cash Date: Mon, 2 Jun 2008 14:13:48 -0400 Subject: [PATCH] Reduce for conses --- extra/lisp/conses/conses.factor | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extra/lisp/conses/conses.factor b/extra/lisp/conses/conses.factor index 3fdbc25b0e..c715ac890a 100644 --- a/extra/lisp/conses/conses.factor +++ b/extra/lisp/conses/conses.factor @@ -20,7 +20,12 @@ TUPLE: cons car cdr ; cons [ swap >>cdr ] reduce ; : (map-cons) ( acc cons quot -- seq ) - over null? [ 2drop ] [ [ uncons ] dip [ call ] keep swapd [ suffix ] 2dip (map-cons) ] if ; + over null? [ 2drop ] + [ [ uncons ] dip [ call ] keep swapd [ suffix ] 2dip (map-cons) ] if ; : map-cons ( cons quot -- seq ) - [ { } clone ] 2dip (map-cons) ; \ No newline at end of file + [ { } clone ] 2dip (map-cons) ; + +: reduce-cons ( cons identity quot -- result ) + pick null? [ drop nip ] + [ [ uncons ] 2dip swapd [ call ] keep reduce-cons ] if ; \ No newline at end of file