keithlisp/doc/stdlib_forms.md

1.5 KiB

Special Forms

Special forms are constructs that Keithlisp evaluates differently from other S-expressions.

quote

quote form

quote returns form as-is, without performing any evaluation on it.

cond

cond {(test {body-form}*)}*

cond is Keithlisp's basic conditional operator. It consists of zero or more clauses (a test, followed by zero or more body-forms).

cond evaluates the test of each clause in order. If the result is non-nil, cond skips all remaining clauses, evaluates each body-form, and returns the result of the last one (or the result of test if the clause has no body-forms). Otherwise, if all tests evaluate to nil, or no clauses were given, cond returns nil.

let

let ({var | (var value)}*) {body-form}*

let defines locally scoped variables in Keithlisp. It consists of a list of variable definitions, followed by zero or more body-forms.

For each variable definition, let evaluates value if it exists, and initializes var to the result. If value does not exist, nil is used instead. If a variable named var exists outside the scope of let, it will be preserved in the syms-alist, but hidden underneath the locally scoped entry.

let evaluates each body-form in sequence and returns the result of the last one. Before returning, it removes the topmost entry for each local variable from the syms-alist. If a locally scoped entry was removed manually, the outer scope's corresponding entry will be removed if it exists.