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
  • 77,472
  • 10
  • 114
  • 243
Tian
  • 288
  • 1
  • 8

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
  • 33,167
  • 1
  • 37
  • 77