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:52:00 -0800 (PST) Organization: http://groups.google.com Message-ID: <111eebd9-3cad-4e1f-96a7-42a12e5267d8@d4g2000prg.googlegroups.com> References: <10f246a9-2a9b-477e-806d-7e3b38ce2607@i29g2000prf.googlegroups.com> <5r81u5F131t6qU1@mid.individual.net> <85k5o13w4q.fsf@lola.goethe.zz> 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 1196354488 8030 80.91.229.12 (29 Nov 2007 16:41:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2007 16:41:28 +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 17:41:35 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 1IxmSB-0005if-KV for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Nov 2007 17:41:31 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxmRv-0001LV-UP for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Nov 2007 11:41:15 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!d4g2000prg.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 48 Original-NNTP-Posting-Host: 68.51.125.199 Original-X-Trace: posting.google.com 1196351520 1566 127.0.0.1 (29 Nov 2007 15:52:00 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 29 Nov 2007 15:52:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d4g2000prg.googlegroups.com; posting-host=68.51.125.199; 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:154261 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:49689 Archived-At: On Nov 29, 10:32 am, David Kastrup wrote: > apatheticagnostic writes: > > 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!"))))) > > [fixed to omit the utterly pointless eval:] > > >> (defun test-call (x) > >> (funcall (car (cdr (assoc x sample-alist))))) > > 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. > > lambda is self-quoting. It is preferable not to quote it nevertheless, > because then the byte compiler can compile and optimize it. Ahh that's nice to know. > However, that was not the problem. The problem is that (cdr '(a b)) is > not b, but rather something equal to '(b). Oh, I think I get it - because lists are normally a strung-along . . . list . . . of thing and pointer to next thing without the . syntax, right? Because (cdr '(a b)) is '(b . ()) -> '(b) whereas (cdr '(a . b)) is just b.(there's no implicit cdr of b, because we're assigning the car and cdr of '(a . b) directly, skipping over the auto-list- construction stuff.