Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lisp newbie-ass question (CL)

Name: Anonymous 2011-06-28 4:29

I want to return the value from a list that looks like(key value). I've got an alist like ((a 1) (b 2) (c 3)) (as alists go), and I get a value given a key with assoc, but the returned value for (assoc 'a myalist) is (A 1).

I can get just the key from that with cdr, but that will return (1), still a list, and I might want to use that value eg. for addition.  So I do: (car (cdr (assoc 'a myalist))) to get 1

Is this as good as any other way?  Or is there some other preferred way of doing it, maybe with 1 function instead of (car (cdr (key val)) or something?

I'm really new to Lisp, so any useful information at all is appreciated.

Name: Anonymous 2011-06-28 12:17

for key-value pairs use pairs, not sublists.

((a . 1) (b . 2) (c . 3))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List