[ [ 1 ] 5 ndip ] must-infer
{ 1 2 3 4 } [ 2 3 4 [ 1 ] 3 ndip ] unit-test
+[ [ 1 2 3 ] 2 3 nrotates ] must-infer
+[ [ 1 2 3 ] 2 3 -nrotates ] must-infer
+{ 1 2 3 4 } [ 1 2 3 4 4 4 nrotates ] unit-test
+{ 1 2 3 4 } [ 1 2 3 4 4 4 -nrotates ] unit-test
+{ 4 1 2 3 } [ 1 2 3 4 1 4 -nrotates ] unit-test
+
[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer
[ 1 2 3 4 5 2 '[ drop drop drop drop drop _ ] 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
memoize.private sequences ;
IN: generalizations
-! These words can be inline combinators the word does no math on
-! the input parameters, e.g. n.
+! These words can be inline combinators when the word does no math
+! on the input parameters, e.g. n.
! If math is done, the word needs to be a macro so the math can
! be done at compile-time.
<<
MACRO: -nrot ( n -- quot )
1 - [ ] [ '[ swap _ dip ] ] repeat ;
+: ndip ( n -- )
+ [ [ dip ] curry ] swap call-n call ; inline
+
+: nrotates ( n depth -- quot )
+ '[ _ [ _ nrot ] times ] call ; inline
+
+: -nrotates ( n depth -- quot )
+ '[ _ [ _ -nrot ] times ] call ; inline
+
: ndrop ( n -- )
[ drop ] swap call-n ; inline
: nnip ( n -- )
'[ _ ndrop ] dip ; inline
-: ndip ( n -- )
- [ [ dip ] curry ] swap call-n call ; inline
-
: nkeep ( n -- )
dup '[ [ _ ndup ] dip _ ndip ] call ; inline