Reverse Forth stack

Plain Text

Public Domain

Reverse the top n elements of the stack in Forth

Download (right click, save as, rename as appropriate)

Embed

1
2
: reverse ( x_1 x_2 ... x_n-1 x_n n -- x_n x_n-1 ... x_2 x_1 )
 0 u+do i roll loop ;