Common Lisp:#+ nil是什么? [英] Common Lisp: What does #+nil?

查看:85
本文介绍了Common Lisp:#+ nil是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前几天(也许是昨天),我对#+ nil 读取时间条件感到困惑/billstclair/defperson/blob/master/defperson.lisp#L289\">https://github.com/billstclair/defperson/blob/master/defperson.lisp#L289 。

The other day (perhaps yesterday) I was quite perplexed about this #+nil read-time conditional found in https://github.com/billstclair/defperson/blob/master/defperson.lisp#L289.

经过深思熟虑,我得出的结论是,这是注释代码的非常灵活的方法。有人可以确认吗?

After some deep thinking I came to the conclusion that this is very lispy way of commenting out code. Can someone confirm this?

也许我的假设是完全错误的。无论如何,请提前致谢。

Perhaps my assumptions are completely wrong. Anyway, thanks in advance.

推荐答案

请参见 CLHS 2.4.8.17 Sharpsign Plus

要对输入中的表达式进行条件化,Common Lisp使用功能< a href = http://www.lispworks.com/documentation/HyperSpec/Body/24_aba.htm rel = nofollow>表达式。

To conditionalize reading expressions from input, Common Lisp uses feature expressions.

在这种情况下,它已用于注释表单。

这是读者的一部分。 #+ 查看下一个项目(通常是具有相同名称的关键字符号)是否是列表的成员 *功能* 。如果是,则正常读取下一个项目,否则将跳过该项目。通常:NIL 不是该列表的成员,因此将跳过该项目。因此,它对Lisp隐藏了表达式。可能有一个Lisp实现,但无法实现: NIL Lisp的新实现。在 *功能* 列表上可能带有符号:NIL ,以指示实现的名称。

It's a part of the reader. #+ looks if the next item, usually as a keyword symbol with the same name, is a member of the list *features*. If yes, the then next item is read as normal, if not, it is skipped.. Usually :NIL is not a member of that list, so the item is skipped. Thus it hides the expression from Lisp. There might have been a Lisp implementation, where this would not work : NIL, New Implementation of Lisp. It might have had the symbol :NIL on the *features* list, to indicate the name of the implementation.

默认情况下,关键字 NIL >包:

Features like NIL are by default read in the keyword package:


  • #+ NIL ->查找:NIL cl:*功能*

  • #+ CL: NIL ->在 cl:* features * CL:NIL >
  • #+NIL -> looks for :NIL in cl:*features*
  • #+CL:NIL -> looks for CL:NIL in cl:*features*

示例

(let ((string1 "#+nil foo bar"))             ; string to read from

  (print (read-from-string string1))         ; read from the string

  (let ((*features* (cons :nil *features*))) ; add :NIL to *features*
    (print (read-from-string string1)))      ; read from the string

  (values))                                  ; return no values

它打印:

BAR 
FOO 

请注意Common Lisp还有其他注释表格的方法:

Note that Common Lisp has other ways to comment out forms:

; (sin 3) should we use that?

#| (sin 3)  should we use that?
   (cos 3)  or this?            |#

这篇关于Common Lisp:#+ nil是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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