Files in directory /sxbuiltins in any check-in
sxbuiltins - a collections of predefined functions to work with symbolic expressions
This package provides a collection of functions that can be used when symbolic
expressions are evaluated (as defined in package
Callable functions allow to compute with objects. All arguments are evaluated before the function is called with these evaluated values as arguments.
(+ 2 5 7) calculates the sum of these three numbers, resulting
in the number value
* is the symbol that evaluates to the
multiplication function, while the symbol
/ evaluates to the division
(= a b) returns a boolean "true" value, if the symbols
evaluate to equal values.
Syntax functions provide a way to interpret some symbolic expression with a special evaluation scheme. In most cases, it is not desired to evaluate all arguments of a function.
For example, the expression
(if COND TRUE FALSE) should evaluate the value
COND. Depending on its value, either
FALSE must be evaluated,
but not true. Otherwise, the expression
(if (= a 0) 'error (/ 10 a)) will not
a is equal to the number zero, when all arguments to a hypothetical
if function are evaluated before calling the function. An error would be
An interesting syntax function is
(lambda PARAMS OBJ1 OBJ2 ...). When
evaluated, it creates a user-defined callable function.
ARGS is typically
a list that specifies the parameters of the function, while
... are objects that are evaluated sequentially in the freshly created new
environment of that function. The result of the last object is the result of
the function call. The environment is first the mapping of the parameter names
to the argument values, and second the pre-existing environment where
A simple user-defined function is a function that adds the number seven to
its single argument:
(lambda (x) (+ c 7)). Since the result of the
function is a callable, you are allowed to put it as a first object into a
((lambda (x) (+ x 7)) 10). This binds the number
10 to the symbol
and calls the function, resulting in a value of
Other syntax functions provide a way to update the current evaluation
(defvar SYMBOL OBJ) binds the value of
OBJ to the symbol
SYMBOL. Later, the binding may be changed.
(defvar add7 (lambda (x) (+ x 7))) is a little verbose, there is a
(defun add7 (x) (+x 7)). Then you can evaluate
If you want the binding to be constant, i.e. that it cannot be updated later,
you should use the form
(defconst SYMBOL OBJ).
lambda creates an user-defined callable function, the is a form to
create an user-defined syntax function:
(defmacro NAME PARAMS OBJ1 ...). Such
a syntax function typically creates a list that will be evaluated separately.
For example, there is an user-defined syntax function that sequentially
evaluates its arguments and stops if a boolean "false" value is found:
OBJ1 ...). If all arguments evaluate to a boolean "true" value,
a "true" value, of course. Here is its definition:
(defconst T 'T) ; a simple true value (defmacro and args (cond ((null? args) T) ((null? (cdr args)) (car args)) (T `(if ,(car args) (and ,@(cdr args))))))
if are predefined syntax functions,
predefined callable functions.