How to pass lambda expression in Elisp

So, I'm trying to create a universal web search function in Elisp:

(defun look-up-base (url-formatter) (let (search url) (setq search(thing-at-point 'symbol)) (setq url (url-formatter search)) (browse-url url)) ) 

This function will simply take the word under the cursor, format the word for web search using url-formatter, and then open the search bar in a web browser to perform the search.

Then I try to implement a function that will substitute Google words under the cursor, using the previous function as the basis.

 (defun google () (interactive) (look-up-base (lambda (search) (concat "http://www.google.com/search?q=" search)))) 

Emacs will not complain if I try to evaluate it, but when I try to use it, Emacs gives me this error message:

 setq: Symbol function definition is void: url-formatter 

And I do not know why this is happening. I don’t see anything wrong with the function, what am I doing wrong?

+4
source share
1 answer

I think you need to use funcall :

Instead of (url-formatter search) you should have (funcall url-formatter search) .

Lisp expects the function name to be the first element of the list. If instead you have a character associated with a lambda expression or function name, you need to use funcall .

+9
source

Source: https://habr.com/ru/post/1344330/


All Articles