From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Accessing an element in an associativity list Date: 9 Sep 2008 13:28:34 GMT Message-ID: References: <42fc0e67-edf3-41e1-baea-eab3d46bbf2d@73g2000hsx.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1220967696 14583 80.91.229.12 (9 Sep 2008 13:41:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Sep 2008 13:41:36 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 09 15:42:31 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kd3UC-0002uT-PY for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2008 15:42:29 +0200 Original-Received: from localhost ([127.0.0.1]:45794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kd3TC-0006oP-F0 for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2008 09:41:26 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-X-Trace: individual.net ttPfRQC4x1aflNOCu3QyPwvH5LjUYCfOLm6HSd/qX6outzzOH3 Cancel-Lock: sha1:Ju6AqAvPuiAtbL6PIHlkFqkboDE= Mail-Copies-To: nobody X-Editor: Emacs of course! User-Agent: slrn/0.9.8.1 (Linux) Original-Xref: news.stanford.edu gnu.emacs.help:162023 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:57363 Archived-At: Nordlöw wrote: > I have the following list of lists structure > > (defvar c++-stl-containers > '( > ("string" "" "String of char.") > ("wstring" "" "String of wide char (wchar_t).") > ("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 of char.") ("wstring" "" "String of wide char (wchar_t).") ("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 > "" > > 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 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)