[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Accessing an element in an associativity list
From: |
Tassilo Horn |
Subject: |
Re: Accessing an element in an associativity list |
Date: |
Tue, 09 Sep 2008 16:47:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Joost Kremers <joostkremers@yahoo.com> writes:
Hi!
> (defvar c++-stl-containers
> '(("string" "<string>" "String of char.")
> ("wstring" "<wstring>" "String of wide char (wchar_t).")
> ("vector" "<vector>" "Vectors contain contiguous elements stored as an
> array.")))
>
>> and I want to do something like this:
>> (index-first 'c++-stl-containers "string" 2)
>> should evaluate to
>> "<string>"
>>
>> Is there any emacs lisp convenience function for accessing a row
>> given its, say, first (key) element?
>
> you can use ASSOC:
>
> (assoc "string" c++-stl-containers)
>
> ===> ("string" "<string>" "String of char.")
For the sake of completeness: To get to "<string>" from the key
"string" you'd use
(cadr (assoc "string" c++-stl-containers))
here, which is a shortcut for
(car (cdr (assoc "string" c++-stl-containers))).
Or you could use one of
(nth 1 (assoc "string" c++-stl-containers))
(second (assoc "string" c++-stl-containers)).
Bye,
Tassilo