Repository navigation
Expressions
A program in do-it is made of a sequence of expressions.
Do-it has these three types of expressions:
- Self-evaluating expressions
- Variable references
- Procedure applications
- Special forms
A self-evaluating expression is a constant. Currently the only self-evaluating expressions are:
- Fixnums (do-it currently doesn't bother to check that an integer will fit in a fixnum…), e.g.
4 - Booleans, i.e.
#tfor true or#ffor false - Characters, e.g.
#\a - Strings of characters, e.g.
"Hello, world!"
A variable reference is simply a symbol (identifier) that is the name of the variable to be referenced.
Note: Variables in do-it only have dynamic extent.
A procedure application takes the form (<operator> <operands>). <operator> is a symbol that is the name of a procedure. (Like LISP, do-it has separate namespaces for variables and procedures.) The <operands> can be any type of expression, and their values are passed as arguments to the procedure.
Do-it is call-by-value, so all the arguments are evaluated, then pushed onto the stack, and then the procedure is called.
Most of the expression types in do-it are special forms. Special forms' "arguments" do not have to be expressions to be evaluated, and may be evaluated more than once.
Quote returns <datum> without evaluating it. (Note that not all objects that Scheme can read are supported by do-it at runtime, currently only the same objects that are self-evaluating. Actually the only type of object in do-it is a machine word.) The second form is an abbreviation for the first form.
Begin evaluates all the expressions in <body> sequentially and returns the value of the last one.
If <test> evaluates to #f or zero, then if <alternative> present it is evaluated, and if it is not present nothing happens. If <test> evaluates to #t, then <consequent> is evaluated.
While repeatedly evaluates <body> (as by begin, in fact the compiler adds a begin around the body), as long as <test> evaluates to true.
Return immediately exits from the procedure or program, returning the result of <expression> if it is present.
Defproc defines a procedure, like LISP's defun. (Like LISP, do-it has seperate namespaces for variables and procedures.) It creates a procedure named <name>. When the procedure is called, the <parameters> are bound to their respective arguments and the <body> is executed as by begin. The parameters and all variables bound by the procedure are local to the procedure.
Note: defproc is (currently) only for use at the top level. Don't use it inside procedures.
Procedure returns the address of the procedure named <name>, which can be called with the special form call.
Call evaluates <procedure pointer> and <operands>, then applies the procedure the value of <procedure pointer> points to to the values of the <operands>.
Define a macro named <name>, written in Scheme. Afterwards, when an expression like (<name> <datum> ...) is encountered, <body> is evaluated as Scheme code by the Scheme interpreter do-it is running on, with the <parameters> bound to the <datums>.
Defvar defines the variable <name>, and sets it to <init> if it is present. Note: Variables in do-it only have dynamic extent.
Set is the assignment operator. It replaces the value of the variable <name> with the value of <expression>.
This is the same as
(begin
<init>
(while <test>
<body>
<step>))e.g.
(for (set i 0) (<= i 20) (set i (+ i 1))
(printf "%d" i)
(newline))will print all the integers from 0 to 20 (inclusive).