]> gitweb.factorcode.org Git - factor.git/commitdiff
Clean up short-circuit combinators
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 21 Nov 2008 10:36:18 +0000 (04:36 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 21 Nov 2008 10:36:18 +0000 (04:36 -0600)
basis/combinators/short-circuit/short-circuit-docs.factor
basis/combinators/short-circuit/short-circuit.factor
basis/combinators/short-circuit/smart/smart.factor

index 54fc3aac432261c7dc2e9eab7148d3c5e38a4711..b1e4a6cf215f35158e2d8adf8e0d0f738430c7ec 100644 (file)
@@ -52,17 +52,17 @@ HELP: 3||
      { "quot" quotation } }
 { $description "Returns true if any quotation in the sequence returns true. Each quotation takes the same three elements from the datastack and must return a boolean." } ;
 
-HELP: n&&-rewrite
+HELP: n&&
 { $values
      { "quots" "a sequence of quotations" } { "N" integer }
      { "quot" quotation } }
-{ $description "A macro that reqrites the code to pass " { $snippet "N" } " parameters from the stack to each AND quotation." } ;
+{ $description "A macro that reqrites the code to pass " { $snippet "n" } " parameters from the stack to each AND quotation." } ;
 
-HELP: n||-rewrite
+HELP: n||
 { $values
-     { "quots" "a sequence of quotations" } { "N" integer }
+     { "quots" "a sequence of quotations" } { "n" integer }
      { "quot" quotation } }
-{ $description "A macro that reqrites the code to pass " { $snippet "N" } " parameters from the stack to each OR quotation." } ;
+{ $description "A macro that reqrites the code to pass " { $snippet "n" } " parameters from the stack to each OR quotation." } ;
 
 ARTICLE: "combinators.short-circuit" "Short-circuit combinators"
 "The " { $vocab-link "combinators.short-circuit" } " vocabulary stops a computation early once a condition is met." $nl
@@ -77,8 +77,8 @@ ARTICLE: "combinators.short-circuit" "Short-circuit combinators"
 { $subsection 2|| }
 { $subsection 3|| }
 "Generalized combinators:"
-{ $subsection n&&-rewrite }
-{ $subsection n||-rewrite }
+{ $subsection n&& }
+{ $subsection n|| }
 ;
 
 ABOUT: "combinators.short-circuit"
index e6a4bfe913e5bb138890b099c949943df03ccc2c..2b4e522789f2cc4d1102c8b960d541c5fb779c35 100644 (file)
@@ -3,12 +3,10 @@ locals generalizations macros fry ;
 IN: combinators.short-circuit
 
 MACRO:: n&& ( quots n -- quot )
-    [let | pairs [
-        quots [| q | { [ drop n ndup q dup not ] [ drop n ndrop f ] } ] map
-        { [ t ] [ n nnip ] } suffix
-    ] |
-        [ f pairs cond ]
-    ] ;
+    [ f ]
+    quots [| q | { [ drop n ndup q call dup not ] [ drop n ndrop f ] } ] map
+    [ n nnip ] suffix 1array
+    [ cond ] 3append ;
 
 MACRO: 0&& ( quots -- quot ) '[ _ 0 n&& ] ;
 MACRO: 1&& ( quots -- quot ) '[ _ 1 n&& ] ;
@@ -16,13 +14,11 @@ MACRO: 2&& ( quots -- quot ) '[ _ 2 n&& ] ;
 MACRO: 3&& ( quots -- quot ) '[ _ 3 n&& ] ;
 
 MACRO:: n|| ( quots n -- quot )
-    [let | pairs [
-        quots
-        [| q | { [ drop n ndup q dup ] [ n nnip ] } ] map
-        { [ drop n ndrop t ] [ f ] } suffix
-    ] |
-        [ f pairs cond ]
-    ] ;
+    [ f ]
+    quots
+    [| q | { [ drop n ndup q call dup ] [ n nnip ] } ] map
+    { [ drop n ndrop t ] [ f ] } suffix 1array
+    [ cond ] 3append ;
 
 MACRO: 0|| ( quots -- quot ) '[ _ 0 n|| ] ;
 MACRO: 1|| ( quots -- quot ) '[ _ 1 n|| ] ;
index ca659cacbef83ad0d68ea36b8028c54a2f230c76..b80e7294d15e064c926a36a09ff732c2cb1eaebe 100644 (file)
@@ -1,7 +1,5 @@
-
 USING: kernel sequences math stack-checker effects accessors macros
-       combinators.short-circuit ;
-
+fry combinators.short-circuit ;
 IN: combinators.short-circuit.smart
 
 <PRIVATE
@@ -13,6 +11,6 @@ IN: combinators.short-circuit.smart
 
 PRIVATE>
 
-MACRO: && ( quots -- quot ) dup arity n&&-rewrite ;
+MACRO: && ( quots -- quot ) dup arity '[ _ _ n&& ] ;
 
-MACRO: || ( quots -- quot ) dup arity n||-rewrite ;
+MACRO: || ( quots -- quot ) dup arity '[ _ _ n|| ] ;