unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: apatheticagnostic <apatheticagnostic@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp - anonymous function in an association list?
Date: Thu, 29 Nov 2007 07:04:29 -0800 (PST)	[thread overview]
Message-ID: <8174d5ed-b956-4775-b209-759cc07620bf@j20g2000hsi.googlegroups.com> (raw)
In-Reply-To: de593600-4a24-49e4-9210-a8aa1bc624cd@a35g2000prf.googlegroups.com

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	other threads:[~2007-11-29 15:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-29 14:00 elisp - anonymous function in an association list? apatheticagnostic
2007-11-29 14:50 ` Marc Tfardy
2007-11-29 15:01   ` apatheticagnostic
2007-11-29 15:04     ` apatheticagnostic [this message]
2007-11-30  0:08       ` Johan Bockgård
2007-11-29 15:32     ` David Kastrup
2007-11-29 15:52       ` apatheticagnostic
2007-11-29 21:24       ` Barry Margolin
2007-11-29 15:41 ` Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8174d5ed-b956-4775-b209-759cc07620bf@j20g2000hsi.googlegroups.com \
    --to=apatheticagnostic@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).