add an "nspin" generalization

db4
Joe Groff 2009-10-08 11:34:20 -05:00
parent 3a1bb22618
commit 5a2a99128b
3 changed files with 12 additions and 0 deletions

View File

@ -303,6 +303,12 @@ HELP: ntuck
} }
{ $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." } ; { $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." } ;
HELP: nspin
{ $values
{ "n" integer }
}
{ $description "A generalization of " { $link spin } " that can work for any stack depth. The top " { $snippet "n" } " items will be reversed in order." } ;
ARTICLE: "sequence-generalizations" "Generalized sequence operations" ARTICLE: "sequence-generalizations" "Generalized sequence operations"
{ $subsections { $subsections
narray narray
@ -321,6 +327,7 @@ ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
nnip nnip
ndrop ndrop
ntuck ntuck
nspin
mnswap mnswap
nweave nweave
} ; } ;

View File

@ -26,6 +26,8 @@ IN: generalizations.tests
{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test { 0 } [ 0 1 2 3 4 4 ndrop ] unit-test
[ [ 1 ] 5 ndip ] must-infer [ [ 1 ] 5 ndip ] must-infer
[ 1 2 3 4 ] [ 2 3 4 [ 1 ] 3 ndip ] unit-test [ 1 2 3 4 ] [ 2 3 4 [ 1 ] 3 ndip ] unit-test
[ 5 nspin ] must-infer
[ 1 5 4 3 2 ] [ 1 2 3 4 5 4 nspin ] unit-test
[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer
{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test { 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test

View File

@ -104,3 +104,6 @@ MACRO: nbi-curry ( n -- )
[ narray concat ] dip like ; inline [ narray concat ] dip like ; inline
: nappend ( n -- seq ) narray concat ; inline : nappend ( n -- seq ) narray concat ; inline
MACRO: nspin ( n -- )
[ [ ] ] swap [ swap [ ] curry compose ] n*quot [ call ] 3append ;