-
Notifications
You must be signed in to change notification settings - Fork 2
Standard Library
gvx edited this page Apr 13, 2011
·
4 revisions
I use the word TOS here to refer to the topmost item on the stack.
The header stack action gives an idea what happens to the stack if a certain function is executed. (a b — c d) means a is TOS before execution, and c is afterwards.
Name | Purpose | Stack action |
---|---|---|
. |
Prints TOS. | (v — ) |
swap |
Swaps the two topmost items on the stack. | (x y — y x) |
(print-stack) |
Debugging only. Prints all items on the stack. Implementation dependent. | N/A |
dup |
Duplicates TOS (note: this does not make copies of stacks, see copy-stack for that). |
(x — x x) |
drop |
Drops TOS. | (x — ) |
get |
Gets the value of a variable by ident. | (i — v) |
getglobal |
Gets the value of a variable by ident, but only look at global scope. | (i — v) |
set |
Sets the value of a variable. | (i v — ) |
setglobal |
Sets the value of a variable, but ignore any relevant local declarations. |
(i v — ) |
local |
Works like set , but makes the variable local to the current closure. |
(i v — ) |
type |
Returns the type of a certain value. Returns an ident of the type. | (v — t) |
[] |
Creates a new stack object and pushes it unto the stack. | ( — s) |
push-to |
Pushes a value to a stack object. | (s v — ) |
pop-from |
Pops a value from a stack object. | (s — v) |
call |
Calls a function if relevant. Pushes value to stack otherwise. call 'abc' is equivalent to abc . |
(x — v?) |
error , raise
|
Raises an error. Takes two arguments: the error name and a trace-back stack. | (n s — ) |
= , equal
|
Compares for equality. Pushes a 1 to the stack if equal, a 0 otherwise. | (x y — b) |
!= , not-equal
|
Compares for inequality. Pushes a 1 to the stack if unequal, a 0 otherwise. | (x y — b) |
< , less
|
Pushes 1 if x < y, 0 otherwise. | (x y — b) |
<= , less-or-equal
|
Pushes 1 if x <= y, 0 otherwise. | (x y — b) |
> , greater
|
Pushes 1 if x > y, 0 otherwise. | (x y — b) |
>= , greater-or-equal
|
Pushes 1 if x >= y, 0 otherwise. | (x y — b) |
not |
The Boolean inverse of the argument | (x — b) |