OutputFinal output manipulation
By default, when your program ends, the GolfScript interpreter outputs everything on the stack, plus a final newline, exactly as if your program ended with:
]puts
What the documentation doesn't directly mention is that the interpreter literally calls the built-in puts
to produce this output, and that this built-in is literally defined as:
{print n print}:puts;
Thus, you can suppress or manipulate the final output by redefining puts
, print
and/or n
(or
if you're feeling really twisted). Here are some examples:
Suppress final newline:
'':n;
(Of course you can leave out the ;
if you don't mind an extra empty string on the stack.)
Suppress final output completely:
{}:puts;puts
NoteThis overwrites puts
with whatever happens to be on top of the stack. If that happens to be something you don't want to execute, you can use e.g. 0:puts;
instead. Note that this also suppresses p
(which is defined as {`puts}:p;
), but you can still use print
for output if you want.