add an "nspin" generalization
parent
3a1bb22618
commit
5a2a99128b
|
@ -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." } ;
|
||||
|
||||
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"
|
||||
{ $subsections
|
||||
narray
|
||||
|
@ -321,6 +327,7 @@ ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
|
|||
nnip
|
||||
ndrop
|
||||
ntuck
|
||||
nspin
|
||||
mnswap
|
||||
nweave
|
||||
} ;
|
||||
|
|
|
@ -26,6 +26,8 @@ IN: generalizations.tests
|
|||
{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test
|
||||
[ [ 1 ] 5 ndip ] must-infer
|
||||
[ 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
|
||||
{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue