37 lines
718 B
Plaintext
37 lines
718 B
Plaintext
{ [s]waps two variables. (varref; varref) → () }
|
|
[
|
|
b: { loads the value at the top of the stack into b }
|
|
a: { loads the value at the top of the stack into a }
|
|
|
|
a;; t: { loads the value stored in the variable stored in a (hence the double dereference) into t }
|
|
b;; a;: { loads the value stored in the variable stored in b into the variable stored in a }
|
|
t; b;: { loads the value stored in t into the variable stored in b }
|
|
]s:
|
|
|
|
{ [p]rints the three variables. }
|
|
[
|
|
"X = " x;. 10,
|
|
"Y = " y;. 10,
|
|
"Z = " z;. 10,
|
|
]p:
|
|
|
|
77444 x:
|
|
12_ y:
|
|
0 z:
|
|
|
|
p;!
|
|
|
|
{ if x > y, swap x and y }
|
|
x;y;> [xys;!] ?
|
|
|
|
{ if y > z, swap y and z }
|
|
y;z;> [yzs;!] ?
|
|
|
|
{ if x > y, swap x and y }
|
|
x;y;> [xys;!] ?
|
|
|
|
"After sorting:
|
|
"
|
|
|
|
p;!
|