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:04:29 -0800 (PST)
User-agent: G2/1.0

On Nov 29, 10:01 am, apatheticagnostic <apatheticagnos...@gmail.com>
wrote:
> 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!

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.


reply via email to

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