XLISP cond

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# cond

Type: | - | special form (fsubr)
Source: | - | xlcont.c

## Syntax

(cond [(pred1 expr1) [(pred2 expr2) ... ]])
  predN - a predicate (NIL / non-NIL) expression
  exprN - an expression
  returns - the value of the first expression whose predicate is non-NIL

## Description

The 'cond' special form evaluates a series of predicate / expression pairs. 'cond' will evaluate each predicate in sequential order until it finds one that returns a non-NIL value. The expression that is associated with the non-NIL value is evaluated. The resulting value of the evaluated expression is returned by 'cond'. If there are no predicates that return a non-NIL value, NIL is returned by 'cond'. Only one expression is evaluated, the first one with a non-NIL predicate. Note that the predicate can be a symbol or expression.

## Examples

    (cond                                       ; sample CONDitional
      ((not T) (print "this won't print"))
      ( NIL    (print "neither will this"))
      ( T      (print "this will print"))
      ( T      (print "won't get here")))       ; prints "this will print"

    (defun print-what (parm)
      (cond                                     ; start of COND
        ((numberp parm) (print "numeric"))      ; check for number
        ((consp parm)   (print "list"))         ; check for list
        ((null parm)    (print "nil"))          ; check for NIL
        (T              (print "something"))))  ; catch-all

    (print-what 'a)       ; prints "something"
    (print-what 12)       ; prints "numeric"
    (print-what NIL)      ; prints "nil"
    (print-what '(a b))   ; prints "list"

See the cond special form in the XLISP 2.0 manual.

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference