From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: apatheticagnostic Newsgroups: gmane.emacs.help Subject: Re: elisp - anonymous function in an association list? Date: Thu, 29 Nov 2007 07:04:29 -0800 (PST) Organization: http://groups.google.com Message-ID: <8174d5ed-b956-4775-b209-759cc07620bf@j20g2000hsi.googlegroups.com> References: <10f246a9-2a9b-477e-806d-7e3b38ce2607@i29g2000prf.googlegroups.com> <5r81u5F131t6qU1@mid.individual.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1196350967 26290 80.91.229.12 (29 Nov 2007 15:42:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2007 15:42:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 29 16:42:54 2007 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 1IxlXL-0002Zd-3l for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Nov 2007 16:42:47 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxlX5-0005ha-Rb for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Nov 2007 10:42:31 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!j20g2000hsi.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Original-NNTP-Posting-Host: 76.251.226.7 Original-X-Trace: posting.google.com 1196348670 24858 127.0.0.1 (29 Nov 2007 15:04:30 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 29 Nov 2007 15:04:30 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j20g2000hsi.googlegroups.com; posting-host=76.251.226.7; posting-account=NwyZJgoAAACP04-gqkVuGlZqnbHiXJ8v User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.10) Gecko/20071126 Ubuntu/7.10 (gutsy) Firefox/2.0.0.10, gzip(gfe), gzip(gfe) Content-Disposition: inline Original-Xref: shelby.stanford.edu gnu.emacs.help:154258 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:49686 Archived-At: On Nov 29, 10:01 am, apatheticagnostic wrote: > On Nov 29, 9:50 am, Marc Tfardy wrote: > > > > > apatheticagnostic schrieb: > > > > take, for example this code showing what I mean: > > > > (defvar sample-alist '(("a" '(lambda () > > > (message "We worked!"))) > > > ("b" #'(lambda () > > > (message "B worked too!"))))) > > > > (defun test-call (x) > > > (funcall (cdr (assoc x sample-alist)))) > > > > (test-call "a") > > > (test-call "b") > > > > Both calls fail, with an error message like so: > > > This seems to work: > > > (defvar sample-alist '(("a" (lambda () (message "We worked!"))) > > ("b" (lambda () (message "B worked too!"))))) > > > (defun test-call (x) > > (funcall (eval (car (cdr (assoc x sample-alist)))))) > > > (test-call "a") > > "We worked!" > > > (test-call "b") > > "B worked too!" > > > regards > > > Marc > > So it does. Well, I feel dumb now. I assumed that I would need to > quote the lambda expressions in some way to prevent them from being > evaluated at definition. > > Thanks a lot! Sorry for the double-post but I wanted to point out that it works with just (funcall (car (cdr (assoc x sample-list)))) and doesn't seem to need the eval.