]> gitweb.factorcode.org Git - factor.git/commitdiff
add an "nspin" generalization
authorJoe Groff <arcata@gmail.com>
Thu, 8 Oct 2009 16:34:20 +0000 (11:34 -0500)
committerJoe Groff <arcata@gmail.com>
Thu, 8 Oct 2009 16:34:20 +0000 (11:34 -0500)
basis/generalizations/generalizations-docs.factor
basis/generalizations/generalizations-tests.factor
basis/generalizations/generalizations.factor

index e05d87132385ffccbcfb8c6f654f643bb8f6ad98..e3a7c2d7e4bbe421be0baf42182f96b6c4000ca9 100644 (file)
@@ -303,6 +303,12 @@ HELP: ntuck
 }\r
 { $description "A generalization of " { $link tuck } " that can work for any stack depth. The top item will be copied and placed " { $snippet "n" } " items down on the stack." } ;\r
 \r
+HELP: nspin\r
+{ $values\r
+    { "n" integer }\r
+}\r
+{ $description "A generalization of " { $link spin } " that can work for any stack depth. The top " { $snippet "n" } " items will be reversed in order." } ;\r
+\r
 ARTICLE: "sequence-generalizations" "Generalized sequence operations"\r
 { $subsections\r
     narray\r
@@ -321,6 +327,7 @@ ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
     nnip\r
     ndrop\r
     ntuck\r
+    nspin\r
     mnswap\r
     nweave\r
 } ;\r
index ec5c1ecc2d70fa0c14d6c0ae2423934d7b043ec2..f95ba632281b219545beb4b3ddfa18a1d1d9a97b 100644 (file)
@@ -26,6 +26,8 @@ IN: generalizations.tests
 { 0 } [ 0 1 2 3 4 4 ndrop ] unit-test\r
 [ [ 1 ] 5 ndip ] must-infer\r
 [ 1 2 3 4 ] [ 2 3 4 [ 1 ] 3 ndip ] unit-test\r
+[ 5 nspin ] must-infer\r
+[ 1 5 4 3 2 ] [ 1 2 3 4 5 4 nspin ] unit-test\r
 \r
 [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer\r
 { 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test\r
index 03d45121962ffe391da6426a418e5cb6757a5c39..a39d549d3b2477a2da326220433a4132eb13beb5 100644 (file)
@@ -104,3 +104,6 @@ MACRO: nbi-curry ( n -- )
     [ narray concat ] dip like ; inline
 
 : nappend ( n -- seq ) narray concat ; inline
+
+MACRO: nspin ( n -- )
+    [ [ ] ] swap [ swap [ ] curry compose ] n*quot [ call ] 3append ;