How to pass a lambda expression in Elisp

北城以北 提交于 2019-12-01 05:24:00

问题


So, I'm trying to make a generic 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 just grab the word under the cursor, format the word for web search using url-formatter and then open up the search string in the web browser to perform the search.

Next, I try to implement a function which will Google the word under the cursor, using the previous function as a 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's function definition is void: url-formatter

And I have no clue why this happens. I can't see anything wrong with the function, what am I doing wrong?


回答1:


I think you need to use funcall:

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

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



来源:https://stackoverflow.com/questions/5357656/how-to-pass-a-lambda-expression-in-elisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!