且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

这个Lisp代码是什么意思?

更新时间:2022-06-05 02:52:15

他们的观点只是可用标识符的范围更大,但是某些字符的语义重载使得编写看起来很容易的代码可能正在做一些奇怪的事情.

Their point is just that the range of available identifiers is larger, but the semantic overloading of certain characters makes it easy to write code that looks like it might be doing something weird.

如果您仔细看一下第一个样本,

If you take a closer look at the first sample,

(lambda (*<8-]= *<8-[= ) (or *<8-]= *<8-[= ))

并将变量*<8-]=重命名为a,并将*<8-[=重命名为b,我们看到它是一个非常简单的函数:

and rename the variable *<8-]= to a, and *<8-[= to b, we see that it's a pretty simple function:

(lambda (a b) (or a b))

在第二种情况下,这只是说明了一点,因为像+<之类的东西不是特殊的运算符或其他任何东西,它们只是名称为"+",您可以将它们用作变量名.同样,我们可以重命名变量并打开

In the second case, it's just making the point that since things like +, <, and so on aren't special operators or anything, they're just symbols with the names "+" and "<", you can use them as variable names. Again, we can rename variables and turn

(defun :-] (<) (= < 2))

进入

(defun :-] (a) (= a 2))

这很不寻常,因为冒号前缀表示一个关键字(Common Lisp中的一种特殊的自评估常量),但是SBCL似乎可以处理它:

This one is rather unusual, since the colon prefix indicates a keyword (a special sort of self-evaluating constant in Common Lisp), but SBCL seems to handle it:

CL-USER> (defun :-] (<) (= < 2))
:-]
CL-USER> (:-] 2)
T
CL-USER> (:-] 3)
NIL

在关键字符号上放置函数定义有些不寻常,但这并不是闻所未闻的,并且很有用.例如,请参见使用关键字命名功能.

Putting function definitions on keyword symbols is somewhat unusual, but it's not unheard of, and can be useful. E.g., see Naming functions with keywords.