zachgates / Gogh

An esoteric, stack-based language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `duplicate top n stack elements` function

luser-dr00g opened this issue · comments

Since you already have a function to rotate the nth item to the top, then with this new function you'd have the ability to iterate bottom-to-top non-destructively over a copy of (portions of) the stack.

More detail about how this works in postscript in my article here:
The count -1 1{-1 roll =}for Idiom.

Specifically it enables you to write a 'print stack' function entirely in user code. And in postscript at least, it can often be used to avoid creation of an array.

Same idea is used in this postscript procedure to concatenate n strings without creating a temp array just to iterate through it. http://stackoverflow.com/a/12472783/733077