assoc, assoc_equal

assoc, assoc_equal — search an association list for a sublist.

Syntax

assoc (s_exp, list)
assoc_equal (s_exp, list)

		

Arguments

s_exp

Any Gamma or Lisp expression.

list

An association list.

Returns

A list whose members are the remainder of the association list starting at the element whose car is eq or equal to the s_exp.

Description

An association list is a list whose elements are also lists, each of which typically contains exactly two elements. assoc searches an association list for a sublist whose car is eq to the given s_exp. assoc_equal uses equal instead of eq for the comparison. If no matching sublist is found, returns nil.

A symbol-indexed association list (or sym-alist) is an association list where the car of each element is a symbol. This is a common construct for implementing property lists and lookup tables. Since symbols are always unique, sym-alists can be searched with assoc instead of assoc_equal.

Example

Gamma> a = 10;
10
Gamma> b = 20;
20
Gamma> c = 30;
30
Gamma> x = list (list(a,15), list(b,25), list(c, 35));
((10 15) (20 25) (30 35))
Gamma> assoc (b,x);
((20 25) (30 35))
Gamma> assoc (20,x);
nil
Gamma> assoc_equal(20,x);
((20 25) (30 35))
Gamma> 
		

See Also

car, cdr, eq, equal, Data Types and Predicates