Skip to main content
Mod Removes Wiki by Doorknob
shorten the code to completely suppress output, extend title
Source Link
Ilmari Karonen
  • 20.8k
  • 4
  • 55
  • 100

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.

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;

Note that this also suppresses p (which is defined as {`puts}:p;), but you can still use print for output if you want.

Final 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

This 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.

Source Link
Ilmari Karonen
  • 20.8k
  • 4
  • 55
  • 100

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;

Note that this also suppresses p (which is defined as {`puts}:p;), but you can still use print for output if you want.