ccQ*_*ein 5 lisp common-lisp reader-macro
今晚我在读cl-fad/load.lisp代码,发现表达式或字符串前面有符号#+:和。#-:
这些符号的含义是什么?
这些是读取时条件化工具:#+让您根据特征表达式#-决定使用什么表达式。read
例如,
#+:allegro (require :osi)
#+:sbcl (require :sb-executable)
Run Code Online (Sandbox Code Playgroud)
意思是当运行在 下时allegro,该模块:osi将被加载,但是当运行在 下时sbcl,该模块:sb-executable将由 加载require。
在所有其他实现下require根本不会被调用,因为read会跳过表单。
您不仅可以检查实现名称,还可以检查特定功能,例如
#+(<= (integer-length most-positive-fixnum) 32)
code for a 32-bit lisp
#+(> (integer-length most-positive-fixnum) 32)
code for a 64-bit lisp
Run Code Online (Sandbox Code Playgroud)
除了根据实现选择代码之外,这还允许人们轻松“注释掉”代码的一部分(即下一个 sexp):
#+(or) (this code will be skipped over by any lisp reader
because (or) returns nil)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3600 次 |
| 最近记录: |