-
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) |
and |
Boolean and. | (x y — b) |
or |
Boolean or. | (x y — b) |
xor |
Boolean exclusive or. | (x y — b) |
+ , add
|
Adds two numbers. | (x y — z) |
- , sub
|
Subtracts two numbers. | (x y — z) |
* , mul
|
Multiplies two numbers. | (x y — z) |
/ , div
|
Divides two numbers. Raises an error if y is zero. | (x y — z) |
% , mod
|
The module of two numbers. | (x y — z) |
return |
Returns from a function. Yes, this is a stdlib function. No, you should not think about that too hard. | ( — ) |
[ |
The ‘stack maker’. This creates a new stack and starts putting values in it until it runs into the special value ']' , which is an Autonym. |
.. ] — ) |
stop-iter |
Pushes the necessary values to signify the end of an iterator to for . Does not actually stop the iteration. |
( — ) |
range |
Returns a range iterator. | (f t — range s f) |
in |
Returns a stack iterator. | (s — in s2 v) |
reversed |
Returns a reversed copy of a stack. | (s — k) |
reversed! |
Reverses stack in place, and pushes it back. | (s — s) |
push-through |
Equivalent to doing s push-to s x
|
(s x — s) |
copy-stack |
Copies a stack. | (s — s2) |
catch-if |
Re-raises error if error name does not match. | (match error — error) |
use |
Uses another Déjà Vu file. Usage: use "mylib.deja"
|
(name — ) |
(ident-count) |
Debugging only. Implementation dependent. Prints the number of idents in use. | ( — ) |
import |
Imports a Python module. Usage: import "mylib"
|
(name — ) |