[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp - anonymous function in an association list?
From: |
Barry Margolin |
Subject: |
Re: elisp - anonymous function in an association list? |
Date: |
Thu, 29 Nov 2007 16:24:57 -0500 |
User-agent: |
MT-NewsWatcher/3.5.2 (Intel Mac OS X) |
In article <85k5o13w4q.fsf@lola.goethe.zz>, David Kastrup <dak@gnu.org>
wrote:
> apatheticagnostic <apatheticagnostic@gmail.com> writes:
>
> > On Nov 29, 9:50 am, Marc Tfardy <m-t-o___CUT__IT...@web.de> 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.
The self-quoting of lambda is not the issue here. He already quoted the
list -- the problem was that he embedded another quote within the list.
This simply quoted the quote.
--
Barry Margolin
Arlington, MA
Re: elisp - anonymous function in an association list?, Tassilo Horn, 2007/11/29