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: Tassilo Horn
Subject: Re: elisp - anonymous function in an association list?
Date: Thu, 29 Nov 2007 16:41:36 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

apatheticagnostic <address@hidden> writes:

Hi,

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

This works:

--8<---------------cut here---------------start------------->8---
(defvar sample-alist '(("a" (lambda ()
                              (message "We worked!")))
                       ("b" (lambda ()
                              (message "B worked too!")))))

(defun test-call (x)
  (funcall (cadr (assoc x sample-alist))))

(test-call "a")
(test-call "b")
--8<---------------cut here---------------end--------------->8---

First, you don't need to quote the lambdas inside the list, which is
already quoted.  Second in `test-call' you don't want the cdr but the
car of the cdr (= cadr) from the assoc.

Bye,
Tassilo





reply via email to

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