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
2

1 Answer 1

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.).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.