From: Joost Kremers <joostkremers@yahoo.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Accessing an element in an associativity list
Date: 9 Sep 2008 13:28:34 GMT [thread overview]
Message-ID: <slrngccud5.32d.joostkremers@j.kremers4.news.arnhem.chello.nl> (raw)
In-Reply-To: 42fc0e67-edf3-41e1-baea-eab3d46bbf2d@73g2000hsx.googlegroups.com
Nordlöw wrote:
> I have the following list of lists structure
>
> (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.")
> )
> )
note, lisp is not C, so don't depend on the parens to show grouping, use
indentation for visual cues. let emacs handle the parentheses. just format
the code like so:
(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.")
ASSOC uses EQUAL as comparison predicate, so you can use it with strings as
keys.
(info "(elisp) Association Lists") for more details.
> I know this is slow but speed is of no
> importance here. Of course if a hash table is as easy to use then of
> course I would like to use that.
(info "(elisp) Hash Tables") should tell you all you need to know. note
that hash tables by default uses eql for key lookup. if you want to use
strings as keys, pass a :test equal argument.
HTH
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
next prev parent reply other threads:[~2008-09-09 13:28 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 [this message]
2008-09-09 14:47 ` Tassilo Horn
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=slrngccud5.32d.joostkremers@j.kremers4.news.arnhem.chello.nl \
--to=joostkremers@yahoo.com \
--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).