$ java lang.Main$ java lang.Main <filename>(this will be ignored) 1 print
( Output:
1.0
)
(even ( nested ) parens will ( be (ignored))) 1 print
( Output:
1.0
)
1 2 + print
( Output:
3.0
)
if 1 2 < do
1 print
end
( Output:
1.0
)
if 1 2 > do
1 print
end
( Output:
)
if 1 2 < do
1 print
else
2 print
end
( Output:
1.0
)
if 1 2 > do
1 print
else
2 print
end
( Output:
2.0
)
5
while 1dup 0 > do
1dup print
1 -
end
1drop
( Output:
5.0
4.0
3.0
2.0
1.0
)
a, b -> c, d
- The stack is expected to have two values,
aandb, on top wherebis on top ofa. - After the function is finished, the stack will have two values,
candd, on top wheredis on top ofc.
<n>dup: Duplicates the topnvalues from the stack (e.g.2dupduplicates the top 2 values) (a1, a2, ..., an -> a1, a2, ..., an, a1, a2, ..., an)<n>drop: Removes the topnvalues from the stack and discards them (e.g.2dropdiscards the top 2 values) (a1, a2, ..., an ->)reverse: Reverses the whole stack (a, b, ..., x -> x, ..., b, a)<n>reverse: Reverses the topnvalues from the stack (e.g.3reversereverses the top 3 values) (a1, a2, ..., an -> an, ..., a2, a1)<m>swap<n>: Swaps the topnvalues and the nextmelements (e.g.2swap2performsa, b, c, d -> c, d, a, b) (a1, a2, ..., am, b1, b2, ..., bn -> b1, b2, ..., bn, a1, a2, ..., am)<m>over<n>: Copies the nextmelements over the topnelements (e.g.2over2performsa, b, c, d -> a, b, c, d, a, b) (a1, a2, ..., am, b1, b2, ..., bn -> a1, a2, ..., am, b1, b2, ..., bn, a1, a2, ..., am)
+: Sums the top 2 values from the stack and pushes the result back (a, b -> a + b)-: Subtracts the top 2 values from the stack and pushes the result back (a, b -> a - b)*: Multiplies the top 2 values from the stack and pushes the result back (a, b -> a * b)/: Divides the top 2 values from the stack and pushes the result back (a, b -> a / b)%: Computes the top value modulo the second from the top value and pushes the result back (a, b -> a % b)divmod: A combination of/and%(a, b -> a / b, a % b)pow: Computes the value of the second from the top value to the power of the top value and pushes the result back (a, b -> pow(a, b))sqrt: Computes the square root of the number on top and pushes the result back (a -> sqrt(a))
sin: Calculates the sine of the top value of the stack and pushes the result back (a -> sin(a))cos: Calculates the cosine of the top value of the stack and pushes the result back (a -> cos(a))
<: Compares the top two values and pushes1if the top value is bigger, otherwise pushes0(a, b -> a < b)<: Compares the top two values and pushes1if the top value is smaller, otherwise pushes0(a, b -> a > b)
print: Prints the top value from the stack and discards it (a --)
fn add + end
1 2 add
"Hello, World" print
1 + (should raise an error before the code is run)
- Figure syntax for function definitions
- Figure how to make sure
ifs andwhiles don't alter the stack