all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp - anonymous function in an association list?
@ 2007-11-29 14:00 apatheticagnostic
  2007-11-29 14:50 ` Marc Tfardy
  2007-11-29 15:41 ` Tassilo Horn
  0 siblings, 2 replies; 9+ messages in thread
From: apatheticagnostic @ 2007-11-29 14:00 UTC (permalink / raw)
  To: help-gnu-emacs

Hey everyone - I'm rather new to the world of lisp in general, so I'm
probably missing something rather obvious here.

I've searched the documentation, tried googling around, searched on
emacswiki, and tried just about every permutation of the following
code that I could think of, and am having no success.

The goal is to have an anonymous function in an association list - I
have a feeling my not being able to get this to work is because of me
not having a clear understanding of how funcall works.

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:

for "b": Debugger entered--Lisp error: (invalid-function ((function
(lambda nil (message "B worked too!")))))

for "a": Debugger entered--Lisp error: (invalid-function ((quote
(lambda nil (message "We worked!")))))

Oh, looks like it's a nested list, maybe calling the car works?

Nope.

So would someone be so kind as to explain what is going on here to
this poor, confused, wanna-be emacs-customizer?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-11-30  0:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.