From 1806a0ce77b082dc35a1652a075842b818133eab Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 23 Jun 2010 14:54:00 -0500 Subject: [PATCH] Add a new smart combinator boa-preserving and document the rest of the smart combinators. Simpler implementation of nullary. --- basis/combinators/smart/smart-docs.factor | 178 ++++++++++++++++++++-- basis/combinators/smart/smart.factor | 9 +- 2 files changed, 173 insertions(+), 14 deletions(-) diff --git a/basis/combinators/smart/smart-docs.factor b/basis/combinators/smart/smart-docs.factor index f02da86c20..fd30bedc8b 100644 --- a/basis/combinators/smart/smart-docs.factor +++ b/basis/combinators/smart/smart-docs.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: help.markup help.syntax kernel quotations math sequences -stack-checker ; +USING: classes.tuple help.markup help.syntax kernel math +quotations sequences stack-checker ; IN: combinators.smart HELP: inputsequence output>array } "Reducing the set of output values:" -{ $subsections reduce-outputs } +{ $subsections + reduce-outputs + map-reduce-outputs +} +"Applying a quotation to groups of elements on the stack:" +{ $subsections smart-apply } "Summing output values:" { $subsections sum-outputs } "Concatenating output values:" @@ -139,6 +285,20 @@ ARTICLE: "combinators.smart" "Smart combinators" append-outputs append-outputs-as } +"Constructing tuples:" +{ $subsections + boa-preserving +} +"Drop the outputs after calling a quotation:" +{ $subsections drop-outputs } +"Cause a quotation to act as a no-op and drop the inputs:" +{ $subsection nullary } +"Preserve the inputs below or above the outputs of the quotation:" +{ $subsections preserving keep-inputs } +"Versions of if that infer how many inputs to keep from the predicate quotation:" +{ $subsections smart-if smart-when smart-unless } +"Versions of if* that infer how many inputs to keep from the predicate quotation:" +{ $subsections smart-if* smart-when* smart-unless* } "New smart combinators can be created by defining " { $link "macros" } " which call " { $link infer } "." ; ABOUT: "combinators.smart" diff --git a/basis/combinators/smart/smart.factor b/basis/combinators/smart/smart.factor index c0ce938abb..d2d9389c44 100644 --- a/basis/combinators/smart/smart.factor +++ b/basis/combinators/smart/smart.factor @@ -46,14 +46,13 @@ MACRO: append-outputs ( quot -- seq ) MACRO: preserving ( quot -- ) [ inputs ] keep '[ _ ndup @ ] ; -MACRO: nullary ( quot -- quot' ) - dup outputs '[ @ _ ndrop ] ; +MACRO: boa-preserving ( tuple-class -- ) + '[ [ _ boa ] preserving ] ; MACRO: dropping ( quot -- quot' ) inputs '[ [ _ ndrop ] ] ; -MACRO: balancing ( quot -- quot' ) - '[ _ [ preserving ] [ dropping ] bi ] ; +MACRO: nullary ( quot -- quot' ) dropping ; MACRO: smart-if ( pred true false -- quot ) '[ _ preserving _ _ if ] ; @@ -65,7 +64,7 @@ MACRO: smart-unless ( pred false -- quot ) '[ _ [ ] _ smart-if ] ; MACRO: smart-if* ( pred true false -- quot ) - '[ _ balancing _ swap _ compose if ] ; + '[ _ [ preserving ] [ dropping ] bi _ swap _ compose if ] ; MACRO: smart-when* ( pred true -- quot ) '[ _ _ [ ] smart-if* ] ;