All Manuals > LispWorks User Guide and Reference Manual > 49 The SYSTEM Package

NextPrevUpTopContentsIndex

cdr-assoc

Function
Summary

A generalized reference for alist elements.

Package

system

Signature

cdr-assoc item alist &key test test-not key => result

(setf cdr-assoc) value item alist => value

Arguments

item

An object.

alist

An association list.

test

A function designator.

test-not

A function designator.

key

A function designator.

value

An object.

Values

result

An object (from alist) or nil.

Description

The functions cdr-assoc and (setf cdr-assoc) provide a generalized reference for elements in an association list. The arguments are all as specified for the Common Lisp function assoc. cdr-assoc and (setf cdr-assoc) read and write the cdr of an element in a manner consistent with the Common Lisp notion of places.

cdr-assoc returns the cdr of the first cons in the alist alist that satisfies the test, or nil if no element of alist matches.

(setf cdr-assoc) modifies the first cons in alist that satisfies the test, setting its cdr to value. If no element of alist matches, then (setf cdr-assoc) constructs a new cons (cons item value) and inserts it in the head of alist.

Example
CL-USER 1 > (defvar *my-alist*
              (list (cons :foo 1)
                    (cons :bar 2)))
*MY-ALIST*
 
CL-USER 2 > (setf (sys:cdr-assoc :bar 
                                 *my-alist*) 3)
3
 
CL-USER 3 > *my-alist*
((:FOO . 1) (:BAR . 3))

LispWorks User Guide and Reference Manual - 13 Feb 2015

NextPrevUpTopContentsIndex