XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

19  Control Constructs


  1. cond - evaluate conditionally
  2. and - the logical AND of a list of expressions
  3. or - the logical OR of a list of expressions
  4. if - evaluate expressions conditionally
  5. when - evaluate only when a condition is true
  6. unless - evaluate only when a condition is false
  7. case - select by case
  8. let - create local bindings
  9. let* - let with sequential binding
  10. flet - create local functions
  11. labels - flet with recursive functions
  12. macrolet - create local macros
  13. catch - evaluate expressions and catch throws
  14. throw - throw to a catch
  15. unwind-protect - protect evaluation of an expression

(cond pair...) - evaluate conditionally
pair - pair consisting of:
(pred expr...)
where:
pred - is a predicate expression
expr - evaluated if the predicate is not NIL
returns - the value of the first expression whose predicate is not NIL

(and expr...) - the logical AND of a list of expressions
expr - the expressions to be anded
returns - NIL if any expression evaluates to NIL, otherwise the value of the last expression
Note: evaluation of expressions stops after the first expression that evaluates to NIL

(or expr...) - the logical OR of a list of expressions
expr - the expressions to be ored
returns - NIL if all expressions evaluate to NIL, otherwise the value of the first non-NIL expression
Note: evaluation of expressions stops after the first expression that does not evaluate to NIL

(if texpr expr1 [expr2]) - evaluate expressions conditionally
texpr - the test expression
expr1 - the expression to be evaluated if texpr is non-NIL
expr2 - the expression to be evaluated if texpr is NIL
returns - the value of the selected expression

(when texpr expr...) - evaluate only when a condition is true
texpr - the test expression
expr - the expression[s] to be evaluated if texpr is non-NIL
returns - the value of the last expression or NIL

(unless texpr expr...) - evaluate only when a condition is false
texpr - the test expression
expr - the expression[s] to be evaluated if texpr is NIL
returns - the value of the last expression or NIL

(case expr case...) - select by case
expr - the selection expression
case - pair consisting of:
(value expr...)
where:
value - is a single expression or a list of expressions (unevaluated)
expr - are expressions to execute if the case matches
returns - the value of the last expression of the matching case

(let (binding...) expr...) - create local bindings
(let* (binding...) expr...) - let with sequential binding
binding - the variable bindings each of which is either:
1) a symbol [which is initialized to NIL]
2) a list whose car is a symbol and whose CADR is an initialization expression
expr - the expressions to be evaluated
returns - the value of the last expression

(flet (binding...) expr...) - create local functions
(labels (binding...) expr...) - flet with recursive functions
(macrolet (binding...) expr...) - create local macros
binding - the function bindings each of which is:
(sym fargs expr...)
where:
sym - the function/macro name
fargs - formal argument list [lambda list]
expr - expressions constituting the body of the function/macro
expr - the expressions to be evaluated
returns - the value of the last expression

(catch sym expr...) - evaluate expressions and catch throws
sym - the catch tag
expr - expressions to evaluate
returns - the value of the last expression the throw expression

(throw sym [expr]) - throw to a catch
sym - the catch tag
expr - the value for the catch to return [defaults to NIL]
returns - never returns

(unwind-protect expr cexpr...) - protect evaluation of an expression
expr - the expression to protect
cexpr - the cleanup expressions
returns - the value of the expression
Note: 'unwind-protect' guarantees to execute the cleanup expressions even if a non-local exit terminates the evaluation of the protected expression

XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next