XLISP consp

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

# consp

Type: | - | predicate function (subr)
Source: | - | xlbfun.c

## Syntax

(consp expr)
  expr - the expression to check
  returns - T if the value is a cons, NIL otherwise

## Description

The 'consp' predicate checks if the 'expr' is a non-empty list. T is returned if 'expr' is a list, NIL is returned otherwise. Note that if the 'expr' is NIL , NIL is returned.

## Examples

    (consp '(a b))                  ; returns T - list
    (consp '(a . b))                ; returns T - dotted pair list
    (consp #'defvar)                ; returns NIL - closure - macro
    (consp (lambda (x) (print x)))  ; returns NIL - closure - lambda
    (consp NIL)                     ; returns NIL - NIL
    (consp #(1 2 3))                ; returns NIL - array
    (consp *standard-output*)       ; returns NIL - stream
    (consp 1.2)                     ; returns NIL - float
    (consp #'quote)                 ; returns NIL - fsubr
    (consp 1)                       ; returns NIL - integer
    (consp object)                  ; returns NIL - object
    (consp "str")                   ; returns NIL - string
    (consp #'car)                   ; returns NIL - subr
    (consp 'a)                      ; returns NIL - symbol

Note: When applied to 'consp', NIL , the empty list, returns a NIL. NIL or '() is used in many places as a list-class or atom-class expression. Both atom and listp , when applied to NIL , return T . If you wish to check for a list where an empty list is still considered a valid list, use the listp predicate.

See the consp predicate function in the XLISP 2.0 manual.

Back to Top

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