1

I would like to define a function that generates lambdas, as such:

(defun my-func (FUNCTION)
    (lambda ()
        (FUNCTION)))

But when I evaluate the following

(defun my-func1 ()
    (message "Hello World"))

(funcall (my-func #'my-func1))

I am told that

Symbol's function definition is void: FUNCTION
Drew
  • 75,699
  • 9
  • 109
  • 225
Tian
  • 288
  • 1
  • 8
  • 1
    Does this answer your question? [How to call a function that is the value of a variable?](https://emacs.stackexchange.com/questions/59204/how-to-call-a-function-that-is-the-value-of-a-variable) – Drew Mar 11 '22 at 16:04
  • `(FUNCTION)` needs to be `(funcall FUNCTION)` – Drew Mar 11 '22 at 16:05

1 Answers1

2

The symbol FUNCTION in your definition of my-func has a local binding for the symbol FUNCTION as variable and not as function.

So you need to call (funcall FUNCTION) in your lambda.

Furthermore, be aware that lexical binding is required for your code to work (FUNCTION must be known to the lambda outside of my-func, i.e., the lambda must actually be a closure.).

Tobias
  • 32,569
  • 1
  • 34
  • 75