]> gitweb.factorcode.org Git - factor.git/commitdiff
add smart-if to combinators.smart
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 19 Aug 2009 09:38:59 +0000 (04:38 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 19 Aug 2009 09:38:59 +0000 (04:38 -0500)
basis/combinators/smart/smart.factor

index 751a1f52e10e83fb40a407c0ddeb65b6a5d6a394..604d2cc8e4e5d992994b9839f2ea1971ac2aab77 100644 (file)
@@ -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