User Tools


Function ADJOIN

Syntax

  • adjoin item list &key key test test-notnew-list

Arguments and Values

Description

Tests whether item is the same as an existing element of list. If the item is not an existing element, adjoin adds it to list (as if by cons) and returns the resulting list; otherwise, nothing is added and the original list is returned.

The test, test-not, and key affect how it is determined whether item is the same as an element of list. For details, see {\secref 17.2.1}.

Examples

(defparameter *slist* '())

*SLIST*

(adjoin 'a *slist*)

(A)

*slist*

NIL

(setf *slist* (adjoin '(test-item 1) *slist*))

((TEST-ITEM 1))

(adjoin '(test-item 1) *slist*)

((TEST-ITEM 1) (TEST-ITEM 1))

(adjoin '(test-item 1) *slist* :test #'equal)

((TEST-ITEM 1))

(adjoin '(new-test-item 1) *slist* :key #'cadr)

((TEST-ITEM 1))

(adjoin '(new-test-item 1) *slist*)

((NEW-TEST-ITEM 1) (TEST-ITEM 1))

Side Effects

None.

Affected By

None.

Exceptional Situations

Should be prepared to signal an error of type type-error if list is not a proper list.

See Also

Macro PUSHNEW, {\secref\TraversalRules}

Example Implementation

(adjoin item list :key fn) ≡ (if (member (funcall fn item) list :key fn) list (cons item list))

Notes

The :test-not parameter is deprecated.

\issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE} \issue{TEST-NOT-IF-NOT:FLUSH-ALL}