From 8e90b92da298df3e31bf7359a67112193f4c20e0 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 9 Nov 2009 00:53:58 -0600 Subject: [PATCH] combinators.smart: add nullary combinator and some tests --- basis/combinators/smart/smart-tests.factor | 6 ++++++ basis/combinators/smart/smart.factor | 3 +++ 2 files changed, 9 insertions(+) diff --git a/basis/combinators/smart/smart-tests.factor b/basis/combinators/smart/smart-tests.factor index 399b4dc36f..bd224919f9 100644 --- a/basis/combinators/smart/smart-tests.factor +++ b/basis/combinators/smart/smart-tests.factor @@ -47,3 +47,9 @@ IN: combinators.smart.tests [ { { 1 2 } { 3 4 } } ] [ nested-smart-combo-test ] unit-test [ 14 ] [ [ 1 2 3 ] [ sq ] [ + ] map-reduce-outputs ] unit-test + +{ 2 3 } [ [ + ] preserving ] must-infer-as + +{ 2 0 } [ [ + ] nullary ] must-infer-as + +{ 2 2 } [ [ [ + ] nullary ] preserving ] must-infer-as diff --git a/basis/combinators/smart/smart.factor b/basis/combinators/smart/smart.factor index a00967742f..91987e0dfa 100644 --- a/basis/combinators/smart/smart.factor +++ b/basis/combinators/smart/smart.factor @@ -46,5 +46,8 @@ MACRO: append-outputs ( quot -- seq ) MACRO: preserving ( quot -- ) [ infer in>> length ] keep '[ _ ndup @ ] ; +MACRO: nullary ( quot -- quot' ) + dup infer out>> length '[ @ _ ndrop ] ; + MACRO: smart-if ( pred true false -- ) '[ _ preserving _ _ if ] ; inline