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

when


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

Syntax

(when test [expr ... ])
test - an expression, NIL or non-NIL
expr - expressions comprising a body of code
returns - the value of the last expression or NIL

Description

The 'when' macro executes the 'expr' forms if 'test' evaluates to a non-NIL value. If 'test' is non-NIL , the value of the last 'expr' is returned as the result. If 'test' is NIL , NIL is returned with none of 'expr' evaluated.

Examples

(when NIL)                  ; returns NIL
(when T)                    ; returns T

(when T (print "hi") 'foo)  ; prints "hi"  returns FOO

(when (listp '(a))
      (print "a list"))     ; prints  "a list"
                            ; returns "a list"

Nyquist: With Nyquist 2.36, the 'when' special form accepts only one 'expr' after the 'test', otherwise an error is generated:

error: too many arguments

If you want to use 'when' with several expressions you must write:

(when test (progn expr1 ... ))

See the when special form in the XLISP 2.0 manual.

  Back to Top


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