John Fremlin | 10 Feb 2009 06:02

cdr assoc (now called alist-get)

For http://common-lisp.net/project/cl-irregsexp/ and in fact for many 
other projects, it is quite handy to have a way of storing key value 
pairs in a table that is more lightweight than a hashtable, and that 
preserves ordering.

The obvious way to do it in Lisp is to store a list like '((key0 . 
value0) (key1 . value1) ...)

However in the ANSI standard there is no easy way to implement (setf 
(gethash key table) value).

(cdr (assoc ...)) is sufficient for lookup.

To that end there is commonly available in extensions a (setf 
cdr-assoc). I posted one to the list before but I had managed to mangle 
it utterly in my last edit of it and it didn't work.

I hope that was why you Alexandrians ignored me . . .

Anyway, one problem with cdr-assoc is that the order of parameters is 
apparently non-standard. To alleviate this problem I have come back with 
a new name, alist-get and also ralist-get (for cdr-rassoc, the 
(value.key) convention).

Feedback very much appreciated!

(declaim (inline racons))
(defun racons (key value ralist)
   (acons value key ralist))

(Continue reading)

Tobias C. Rittweiler | 11 Feb 2009 21:58
Picon

Re: cdr assoc (now called alist-get)

John Fremlin <john <at> fremlin.org> writes:

> I hope that was why you Alexandrians ignored me . . .

No ignoring, it's just the wrong phase of the moon right now.

  -T.

Gmane