普通口号中的# [英] The #' in common lisp

查看:90
本文介绍了普通口号中的#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在《实践通用Lisp》一书的第3章中,有一个类似SQL的select和where函数的示例。这是它的简化版本:

In chapter 3 of Practical Common Lisp book there's an example of a SQL-like select and where functions. Here's a simplified version of it:

(defun where (x) 
   #'(lambda (item)
     (> item x)))

,它的用法如下:

(remove-if-not (where 2) (list 1 2 3 4))

在本书中较早地解释了#'序列用于说明已遵循通过函数名而不是需要评估的变量。我不明白为什么在这里需要它。我试着在没有它的情况下实现 where 函数,并且效果很好:

Earlier in the book it is explained that the #' sequence is used to state that it is followed by a function name, rather than a variable that requires evaluation. I don't understand why it's needed here. I tried implementing the where function without it and it worked as well:

(defun where (x) 
   (lambda (item)
     (> item x)))

我尝试使用它进行谷歌搜索,正如您可以想象的那样,使用这样的字符序列并不是一个非常有成果的搜索。而且我不知道这东西的名字。
上面的代码中为什么需要它吗?

I tried googling for it, and, as you can imagine, with such a sequence of characters it wasn't a very fruitful search. And I don't know the name of this thing. Is there any particular reason why it's needed in the above code?

推荐答案

这就是精确的页面,该页面处理标准宏字符 sharp和单引号。

This is the precise page in Hyperspec which deals with the standard macro character "sharp" followed by "single quote".

为简单起见,此阅读器宏扩展为将以下形式包含在(function< form>) s-expression中。

To make it simple, this reader macro expands to enclose the following form into (function <form>) s-expression. This effectively tells the parser that the form is callable.

lambda 是一个宏,它会生成代码,该代码可以有效地告诉解析器该窗体是可调用的。已经包含(function< form>),但是从历史上和为了保持一致性,通常也使用从阅读器宏中使用尖括号+引号获得的替代形式。 。

lambda is a macro, which generates the code, which already contains the (function <form>), but historically and for consistency, the alternative form, which is obtained from the reader macro with sharp + quote, is often used too.

此处是编写Lambda表达式常见的lisp (另一个StackOverflow问题),其中深入介绍了(lambda< form>)

Here's Writing lambda expressions in common lisp (another StackOverflow question) which covers in-depth the particular case of (lambda <form>)

这篇关于普通口号中的#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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