From b1f9b58781669f092e39b3d42a08c79cf5fa2161 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 19 Aug 2009 04:38:59 -0500 Subject: [PATCH] add smart-if to combinators.smart --- basis/combinators/smart/smart.factor | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/basis/combinators/smart/smart.factor b/basis/combinators/smart/smart.factor index 751a1f52e1..604d2cc8e4 100644 --- a/basis/combinators/smart/smart.factor +++ b/basis/combinators/smart/smart.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors fry generalizations kernel macros math.order -stack-checker math ; +stack-checker math sequences ; IN: combinators.smart MACRO: drop-outputs ( quot -- quot' ) @@ -39,3 +39,9 @@ MACRO: append-outputs-as ( quot exemplar -- newquot ) MACRO: append-outputs ( quot -- seq ) '[ _ { } append-outputs-as ] ; + +MACRO: preserving ( quot -- ) + [ infer in>> length ] keep '[ _ ndup @ ] ; + +MACRO: smart-if ( pred true false -- ) + '[ _ preserving _ _ if ] ; inline