From dfeb610555f43a5bdd01012ce674a2d46e47a79d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 5 Sep 2008 17:27:10 -0500 Subject: [PATCH] document and fix stack effect for 2cleave, 3cleave --- core/combinators/combinators-docs.factor | 14 ++++++++++++++ core/combinators/combinators.factor | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/combinators/combinators-docs.factor b/core/combinators/combinators-docs.factor index 67fde74a92..a494c09b05 100755 --- a/core/combinators/combinators-docs.factor +++ b/core/combinators/combinators-docs.factor @@ -16,6 +16,10 @@ $nl { $subsection while } "Generalization of " { $link bi } " and " { $link tri } ":" { $subsection cleave } +"Generalization of " { $link 2bi } " and " { $link 2tri } ":" +{ $subsection 2cleave } +"Generalization of " { $link 3bi } " and " { $link 3tri } ":" +{ $subsection 3cleave } "Generalization of " { $link bi* } " and " { $link tri* } ":" { $subsection spread } "Two combinators which abstract out nested chains of " { $link if } ":" @@ -50,6 +54,16 @@ HELP: cleave } } ; +HELP: 2cleave +{ $values { "x" object } { "y" object } + { "seq" "a sequence of quotations with stack effect " { $snippet "( x y -- ... )" } } } +{ $description "Applies each quotation to the two objects in turn." } ; + +HELP: 3cleave +{ $values { "x" object } { "y" object } { "z" object } + { "seq" "a sequence of quotations with stack effect " { $snippet "( x y z -- ... )" } } } +{ $description "Applies each quotation to the three objects in turn." } ; + { bi tri cleave } related-words HELP: spread diff --git a/core/combinators/combinators.factor b/core/combinators/combinators.factor index d0c83d0ca2..4a362a7f9d 100755 --- a/core/combinators/combinators.factor +++ b/core/combinators/combinators.factor @@ -13,14 +13,14 @@ IN: combinators [ [ keep ] curry ] map concat [ drop ] append [ ] like ; ! 2cleave -: 2cleave ( x seq -- ) +: 2cleave ( x y seq -- ) [ 2keep ] each 2drop ; : 2cleave>quot ( seq -- quot ) [ [ 2keep ] curry ] map concat [ 2drop ] append [ ] like ; ! 3cleave -: 3cleave ( x seq -- ) +: 3cleave ( x y z seq -- ) [ 3keep ] each 3drop ; : 3cleave>quot ( seq -- quot )