help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: elisp - anonymous function in an association list?


From: apatheticagnostic
Subject: Re: elisp - anonymous function in an association list?
Date: Thu, 29 Nov 2007 07:01:53 -0800 (PST)
User-agent: G2/1.0

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!")))))
>
> (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!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]