]> gitweb.factorcode.org Git - factor.git/commitdiff
Add nsequence
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 7 Sep 2008 04:20:27 +0000 (23:20 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 7 Sep 2008 04:20:27 +0000 (23:20 -0500)
basis/generalizations/generalizations-docs.factor
basis/generalizations/generalizations.factor

index a702f452da6d8764c29d8f499e66b83336b65829..a2b318cb391acc20a16c12dab94cc50801debb88 100755 (executable)
@@ -2,6 +2,16 @@ USING: help.syntax help.markup kernel sequences quotations
 math arrays ;\r
 IN: generalizations\r
 \r
+HELP: nsequence\r
+{ $values { "n" integer } { "seq" "an exemplar" } }\r
+{ $description "A generalization of " { $link 2sequence } ", "\r
+{ $link 3sequence } ", and " { $link 4sequence } " "\r
+"that constructs a sequence from the top " { $snippet "n" } " elements of the stack."\r
+}\r
+{ $examples\r
+    { $example "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }\r
+} ;\r
+\r
 HELP: narray\r
 { $values { "n" integer } }\r
 { $description "A generalization of " { $link 1array } ", "\r
@@ -9,6 +19,8 @@ HELP: narray
 "that constructs an array from the top " { $snippet "n" } " elements of the stack."\r
 } ;\r
 \r
+{ nsequence narray } related-words\r
+\r
 HELP: firstn\r
 { $values { "n" integer } }\r
 { $description "A generalization of " { $link first } ", "\r
@@ -127,11 +139,15 @@ HELP: nkeep
 { $see-also keep nslip } ;\r
 \r
 ARTICLE: "generalizations" "Generalized shuffle words and combinators"\r
-"A number of stack shuffling words and combinators for use in "\r
+"The " { $vocab-link "generalizations" } " vocabulary defines a number of stack shuffling words and combinators for use in "\r
 "macros where the arity of the input quotations depends on an "\r
 "input parameter."\r
+$nl\r
+"Generalized sequence operations:"\r
 { $subsection narray }\r
+{ $subsection nsequence }\r
 { $subsection firstn }\r
+"Generated stack shuffle operations:"\r
 { $subsection ndup }\r
 { $subsection npick }\r
 { $subsection nrot }\r
@@ -139,6 +155,7 @@ ARTICLE: "generalizations" "Generalized shuffle words and combinators"
 { $subsection nnip }\r
 { $subsection ndrop }\r
 { $subsection nrev }\r
+"Generalized combinators:"\r
 { $subsection ndip }\r
 { $subsection nslip }\r
 { $subsection nkeep }\r
index e4d5249a30620115b24a54d43fb35786c386a180..c97e9c7b914e20ded0b17cf0b175fc1399026a63 100755 (executable)
@@ -5,10 +5,13 @@ USING: kernel sequences sequences.private namespaces math
 math.ranges combinators macros quotations fry arrays ;\r
 IN: generalizations\r
 \r
-MACRO: narray ( n -- quot )\r
-    [ <reversed> ] [ '[ , f <array> ] ] bi\r
+MACRO: nsequence ( n seq -- quot )\r
+    [ drop <reversed> ] [ '[ , , new-sequence ] ] 2bi\r
     [ '[ @ [ , swap set-nth-unsafe ] keep ] ] reduce ;\r
 \r
+MACRO: narray ( n -- quot )\r
+    '[ , { } nsequence ] ;\r
+\r
 MACRO: firstn ( n -- )\r
     dup zero? [ drop [ drop ] ] [\r
         [ [ '[ , _ nth-unsafe ] ] map ]\r