XLISP and

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

# and

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

## Syntax

(and [expr1 ... ])
  exprN - an expression
  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

## Description

The 'and' special form evaluates a sequence of expressions and returns the effect of a logical AND on the expressions. If, at any point, an expression is NIL, then NIL is returned as the result of the 'and' function. If all of the expressions have a non-NIL value, the value of the last expression is returned as the result. Evaluation of the expressions will stop when an expression evaluates to NIL, none of the subsequent expressions will be evaluated. If there are no expressions, then 'and' returns T as its result.

## Examples

    (and t t t)  => T
    (and nil t)  => NIL
    (and t nil)  => NIL
    (and)        => T

Some more practical examples:

    > (and T "boo" "hiss" T "rah")
    "rah"    ; return value of AND

    > (and (princ "hi") NIL (princ "ho"))
    hi       ; prints "hi"
    NIL      ; return value of AND

See princ.

    > (setq a 5 b 6)                 ; set up A and B
    6                                ; return value of SETQ

    > (if (and (numberp a)           ; if A is a number
               (numberp b)           ; and B is a number
               (< a b))              ; and A < B
        (print "A is less than B")   ; then do this
        (print "error"))             ; else do this
    "A is less than B"               ; screen output of PRINT
    "A is less than B"               ; return value of IF

See < , if , print, setq.

See also:

- Contents → Control Constructs

Back to Top

XLISP > XLISP 2.0 - Contents - Reference