如何在Elisp中传递lambda表达式 [英] How to pass a lambda expression in Elisp

查看:132
本文介绍了如何在Elisp中传递lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我试图在Elisp中创建一个通用的网页搜索功能:

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

此功能只会抓住光标,使用url-formatter格式化网页搜索的单词,然后在网络浏览器中打开搜索字符串执行搜索。

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.

接下来,我尝试实现函数将Google将光标下的单词作为基础。

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不会抱怨,但是当我尝试使用它时,Emacs给我这个错误信息:

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?

推荐答案

我想你需要使用 funcall

而不是(url-formatter search)你应该有(funcall url-formatter search)

Lisp期望函数的名称作为列表的第一个元素。如果相反,您有一个与lambda表达式或函数名称关联的符号,则需要使用 funcall

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.

这篇关于如何在Elisp中传递lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆