unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Accessing an element in an associativity list
Date: Tue, 09 Sep 2008 16:47:10 +0200	[thread overview]
Message-ID: <87prndfkb5.fsf@thinkpad.tsdh.de> (raw)
In-Reply-To: slrngccud5.32d.joostkremers@j.kremers4.news.arnhem.chello.nl

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





      reply	other threads:[~2008-09-09 14:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-09 13:07 Accessing an element in an associativity list Nordlöw
2008-09-09 13:28 ` Joost Kremers
2008-09-09 14:47   ` Tassilo Horn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87prndfkb5.fsf@thinkpad.tsdh.de \
    --to=tassilo@member.fsf.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).