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
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:
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.
(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 1Is 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.