Skip to main content
Commonmark migration
Source Link

##GolfScript

GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.

4   - Put the number 4 on the stack. Stack content: 4
:echo - Save the value at the top of the stack to the variable echo. Stack content: 4
(   - Decrement the value at the top of the stack by 1. Stack content: 3
2   - Put the number 2 on top of the stack. Stack content: 3 2
+   - Add the two numbers on top of the stack. Stack content: 5
2   - Put the number 2 on top of the stack. Stack content: 5 2
)   - Increment the value at the top of the stack by 1. Stack content: 5 3
;   - Remove the top element from the stack. Stack content: 5

GolfScript will by default print anything left on the stack after execution has finished.

##GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.

4   - Put the number 4 on the stack. Stack content: 4
:echo - Save the value at the top of the stack to the variable echo. Stack content: 4
(   - Decrement the value at the top of the stack by 1. Stack content: 3
2   - Put the number 2 on top of the stack. Stack content: 3 2
+   - Add the two numbers on top of the stack. Stack content: 5
2   - Put the number 2 on top of the stack. Stack content: 5 2
)   - Increment the value at the top of the stack by 1. Stack content: 5 3
;   - Remove the top element from the stack. Stack content: 5

GolfScript will by default print anything left on the stack after execution has finished.

GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.

4   - Put the number 4 on the stack. Stack content: 4
:echo - Save the value at the top of the stack to the variable echo. Stack content: 4
(   - Decrement the value at the top of the stack by 1. Stack content: 3
2   - Put the number 2 on top of the stack. Stack content: 3 2
+   - Add the two numbers on top of the stack. Stack content: 5
2   - Put the number 2 on top of the stack. Stack content: 5 2
)   - Increment the value at the top of the stack by 1. Stack content: 5 3
;   - Remove the top element from the stack. Stack content: 5

GolfScript will by default print anything left on the stack after execution has finished.

Included code explanation.
Source Link
aaaaaaaaaaaa
  • 4.4k
  • 1
  • 17
  • 24

##GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.

4   - Put the number 4 on the stack. Stack content: 4
:echo - Save the value at the top of the stack to the variable echo. Stack content: 4
(   - Decrement the value at the top of the stack by 1. Stack content: 3
2   - Put the number 2 on top of the stack. Stack content: 3 2
+   - Add the two numbers on top of the stack. Stack content: 5
2   - Put the number 2 on top of the stack. Stack content: 5 2
)   - Increment the value at the top of the stack by 1. Stack content: 5 3
;   - Remove the top element from the stack. Stack content: 5

GolfScript will by default print anything left on the stack after execution has finished.

##GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.

##GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.

4   - Put the number 4 on the stack. Stack content: 4
:echo - Save the value at the top of the stack to the variable echo. Stack content: 4
(   - Decrement the value at the top of the stack by 1. Stack content: 3
2   - Put the number 2 on top of the stack. Stack content: 3 2
+   - Add the two numbers on top of the stack. Stack content: 5
2   - Put the number 2 on top of the stack. Stack content: 5 2
)   - Increment the value at the top of the stack by 1. Stack content: 5 3
;   - Remove the top element from the stack. Stack content: 5

GolfScript will by default print anything left on the stack after execution has finished.

Source Link
aaaaaaaaaaaa
  • 4.4k
  • 1
  • 17
  • 24

##GolfScript

4:echo(2+2); 

Prints 5.

Of course GolfScript has a syntax that is markedly different from other languages, this program just happen to look like something Basic or C-ish.