Why do Golfscript examples use pop-and-discard at the start?
;'2706 410'
~{.@\%.}do;
From the GCD example. It looks like the pop and discard at the start wi开发者_运维知识库ll do nothing, so why is it there?
The program starts with the contents of standard input at the top of the stack. The pop discards this unused input so that it is not printed when the program exits.
From the tutorial:
There is no explicit input command in GolfScript, instead when your script is executed, all input from stdin is read first and placed as a string onto the stack.
and:
When your script reaches the end. The contents of the stack are printed automatically.
精彩评论