How to Create a Temporary Function in Emacs Lisp

Posted by Cristian on Stack Overflow See other posts from Stack Overflow or by Cristian
Published on 2010-04-17T05:10:20Z Indexed on 2010/04/17 5:13 UTC
Read the original article Hit count: 468

Filed under:
|
|

I'm making some tedious calls to a bunch of functions, but the parameters will be determined at runtime. I wrote a simple function to keep my code DRY but giving it a name is unnecessary. I don't use this function anywhere else.

I'm trying to do it the way I would in Scheme, but I get a void-function error:

(let ((do-work (lambda (x y z)
                  (do-x x)
                  (do-y y)
                  ;; etc
                  )))
  (cond (test-1 (do-work 'a 'b 'c))
        (test-2 (do-work 'i 'j 'k))))

I could stick it all into an apply (e.g., (apply (lambda ...) (cond ...))) but that isn't very readable. Is there a better way?

© Stack Overflow or respective owner

Related posts about emacs

Related posts about emacs-lisp