From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Accessing an element in an associativity list Date: Tue, 09 Sep 2008 16:47:10 +0200 Message-ID: <87prndfkb5.fsf@thinkpad.tsdh.de> References: <42fc0e67-edf3-41e1-baea-eab3d46bbf2d@73g2000hsx.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1220972059 2487 80.91.229.12 (9 Sep 2008 14:54:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Sep 2008 14:54:19 +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 16:55:11 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 1Kd4Zb-0001Q9-2P for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2008 16:52:07 +0200 Original-Received: from localhost ([127.0.0.1]:39741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kd4Yb-00050R-53 for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Sep 2008 10:51:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kd4X5-0004TH-GN for help-gnu-emacs@gnu.org; Tue, 09 Sep 2008 10:49:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kd4X4-0004SJ-8F for help-gnu-emacs@gnu.org; Tue, 09 Sep 2008 10:49:30 -0400 Original-Received: from [199.232.76.173] (port=54506 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kd4X3-0004SB-MX for help-gnu-emacs@gnu.org; Tue, 09 Sep 2008 10:49:29 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:44692 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kd4X3-0007os-7E for help-gnu-emacs@gnu.org; Tue, 09 Sep 2008 10:49:29 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kd4Ww-0008D6-Cm for help-gnu-emacs@gnu.org; Tue, 09 Sep 2008 14:49:22 +0000 Original-Received: from dhcp188.uni-koblenz.de ([141.26.71.188]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2008 14:49:22 +0000 Original-Received: from tassilo by dhcp188.uni-koblenz.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2008 14:49:22 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 39 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dhcp188.uni-koblenz.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:+eVu0BvhHErFF/+phWB92S9WZps= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:57367 Archived-At: Joost Kremers writes: Hi! > (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.") For the sake of completeness: To get to "" 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