XLISP >
XLISP 2.0 -
Contents -
Reference -
Previous |
Next
caar, cadr
Type: |
- |
function (subr) |
Source: |
- |
xllist.c |
Syntax
- (caar expr)
(cadr expr)
- expr - a list or list expression
returns - the result of the last car
function
Description
The 'caar' and 'cadr' functions go through the list expression and
perform a sequence of car /
cdr operations. The sequence of
operations is performed from right to left. So 'cadr' does a
cdr on the expression, followed by a
car. If at any point the list is
NIL ,
NIL is returned. If at any point a
car operation is performed on an atom
[as opposed to a list] an error is reported:
error: bad argument
Examples
(setq mylist '((1A 1B) (2A 2B) (3A 3B))) ; make a 2-level list
(caar mylist) ; returns 1A
(cadr mylist) ; returns (2A 2B)
(cdar mylist) ; returns (1B)
(cddr mylist) ; returns ((3A 3B))
(caar 'a) ; error: bad argument
(caar nil) ; returns NIL
Note: The 'cx...xr' functions are part of the historical Lisp
functions. In XLISP you probably will find it much more convenient to work
with the modern lisp functions like
nth and
nthcdr. Please read the
list functions page in the
XLISP 2.0 manual.
See the
cxxr
functions in the XLISP 2.0 manual.
Back to Top
XLISP >
XLISP 2.0 -
Contents -
Reference -
Previous |
Next