From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bastien Newsgroups: gmane.emacs.help Subject: Re: Hash tables - how to look up values? Date: Wed, 04 Jul 2012 16:09:40 +0200 Organization: GNU Message-ID: <877guj62jf.fsf@gnu.org> References: <873957d4di.fsf@googlemail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1341410965 23347 80.91.229.3 (4 Jul 2012 14:09:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 4 Jul 2012 14:09:25 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Thorsten Jolitz Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 04 16:09:23 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SmQGg-00059t-1W for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Jul 2012 16:09:22 +0200 Original-Received: from localhost ([::1]:53266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmQGe-0005C2-Ti for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Jul 2012 10:09:20 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmQGV-0005Bd-RM for help-gnu-emacs@gnu.org; Wed, 04 Jul 2012 10:09:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SmQGL-0001SW-Dv for help-gnu-emacs@gnu.org; Wed, 04 Jul 2012 10:09:11 -0400 Original-Received: from mail-we0-f169.google.com ([74.125.82.169]:62333) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SmQGL-0001Pk-4c for help-gnu-emacs@gnu.org; Wed, 04 Jul 2012 10:09:01 -0400 Original-Received: by wefh52 with SMTP id h52so6365990wef.0 for ; Wed, 04 Jul 2012 07:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:organization:references :user-agent:date:message-id:mime-version:content-type; bh=dmECw4+5MNJaJP65qVVgOz+y7rCXiynUAwDG+AWT/Bs=; b=cU+8uwOEILrfh8vaNkbQZ/L3Me1naRAX17rulcMRQkT9zkl3tq+rRYnoA/PUklNGK+ v7luc1DWwxfgW7PtZ2tuCllDS44oeYak2B9ume9xasMs5C12VFrFpn8HxMynaKj4HnyQ 7X/SM30UIh87d7nyvFeLSMGV9Zu0qUGEsoNR/Rq/tU6rnmn1yC+hmLJ7fPcTRSmoPfrF iLeg/7BrDil6JF3MCE9WBd2HBRe3kCyjJPjmG0oiWHfTsl98Z0+XynfVsD0LXMPSHzWx FxetuN2djfKkFPH5+WQSQafD4EBv53X9K8dcoGZlEqJY0UIE2mP+ZGF6ZLGEp2szB2Ou IpRg== Original-Received: by 10.216.215.201 with SMTP id e51mr6199919wep.214.1341410938965; Wed, 04 Jul 2012 07:08:58 -0700 (PDT) Original-Received: from myhost.localdomain (mar75-2-81-56-68-112.fbx.proxad.net. [81.56.68.112]) by mx.google.com with ESMTPS id eu4sm37013244wib.2.2012.07.04.07.08.57 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 Jul 2012 07:08:58 -0700 (PDT) Original-Received: by myhost.localdomain (Postfix, from userid 1000) id D27E28207; Wed, 4 Jul 2012 16:09:41 +0200 (CEST) In-Reply-To: <873957d4di.fsf@googlemail.com> (Thorsten Jolitz's message of "Wed, 04 Jul 2012 15:48:09 +0200") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85653 Archived-At: Hi Thorsten, Thorsten Jolitz writes: > I would need a function that does the opposite of > > ,-------------------- > | (gethash key table) > `-------------------- > > i.e. something like > > ,------------------- > | (getkey val table) > `------------------- > > that returns the corresponding key of a known (string) value in a hash > table (similar to 'rassoc' for alists). > > I could not find such a function - does it exist already? I don't think so. But here is a start: (let (key-found) (maphash (lambda (key val) (when (equal val "my_value") (setq key-found key))) hashtest) key-found) Of course, the shortcoming is that it stops at the first key it finds, and discards multiple keys if several have the same value. HTH, -- Bastien