I'm trying to pass one method to another in elisp, and then have that method execute it. Here is an example:
(defun t1 () "t1") (defun t2 () "t1") (defun call-t (t) ; how do I execute "t"? (t)) ; How do I pass in method reference? (call-t 't1)
Function Call When calling a function with a function parameter, the value passed must be a pointer to a function. Use the function's name (without parentheses) for this: func(print); would call func , passing the print function to it.
Because functions are objects we can pass them as arguments to other functions. Functions that can accept other functions as arguments are also called higher-order functions. In the example below, a function greet is created which takes a function as an argument.
We cannot pass the function as an argument to another function. But we can pass the reference of a function as a parameter by using a function pointer. This process is known as call by reference as the function parameter is passed as a pointer that holds the address of arguments.
I will call what you are passing in a to a function the actual parameters, and where you receive them, the parameters in the function, the formal parameters.
First, I'm not sure that naming your function t
is helping as 't' is used as the truth value in lisp.
That said, the following code works for me:
(defun test-func-1 () "test-func-1" (interactive "*") (insert-string "testing callers")) (defun func-caller (callee) "Execute callee" (funcall callee)) (func-caller 'test-func-1)
Please note the use of 'funcall', which triggers the actual function call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With