2.1 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-form
s).
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-form
s). Otherwise, if all test
s 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-form
s.
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.
defun
(defun ({arg}*) {body-form}*)
defun
defines a new function in Keithlisp. It consists of a list of
argument definitions, followed by zero or more body-form
s.
An argument definition is simply the name of the locally scoped variable
which it should be bound to. &optional
, &rest
, and &key
arguments
are not yet supported.
defmacro
(defmacro ({arg}*) {body-form}*)
defmacro
defines a new macro in Keithlisp. It takes the same arguments
as defun
, but sets the RAWARG
, EVALRES
, and EARLY
flags in the
function definition, making it behave like a macro.