/ n-to-r /

N>R

description:

N>R "n-to-r"

( xn ... x1 n -- ) ( R: -- x1 ... xn n )

Take n off the data stack. Repeat n times: move the top
data stack item to the return stack. After that, place n
onto the return stack.


note:

The words N>R and NR> are a means to store the information returned by words
like SAVE-INPUT to the return stack and thus unblock the data stack


See:
NR> n-r-from/index.html


Implementation:


( Thanks to Coos Haak for posting this high-level code)

\ Push n+1 elements on the return stack.
: N>R ( S: xn .. x1 n -- ) ( R: -- x1 .. xn n )
    DUP
    BEGIN DUP
    WHILE ROT R> SWAP >R >R 1-
    REPEAT
    DROP R> SWAP >R >R
; \ COMPILE-ONLY

This implementation assumes presence of a single-cell return address
on the return stack. This is why there is R> SWAP >R >R instead of
just >R .

BTW, R> SWAP >R >R is the same as R> 2>R , so you may prefer:

\ Push n+1 elements on the return stack.
: N>R ( S: xn .. x1 n -- ) ( R: -- x1 .. xn n )
    DUP
    BEGIN DUP
    WHILE ROT R> 2>R 1-
    REPEAT
    DROP R> 2>R
; \ COMPILE-ONLY



generated Wed Jul 23 02:53:35 2003mlg