}\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
nnip\r
ndrop\r
ntuck\r
+ nspin\r
mnswap\r
nweave\r
} ;\r
{ 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
[ narray concat ] dip like ; inline
: nappend ( n -- seq ) narray concat ; inline
+
+MACRO: nspin ( n -- )
+ [ [ ] ] swap [ swap [ ] curry compose ] n*quot [ call ] 3append ;