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

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

elisp - anonymous function in an association list?


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

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?


reply via email to

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