这个Lisp代码是什么意思? [英] What does this Lisp code mean?

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

问题描述

https://www.thc.org/root/phun/unmaintain.html Lisp被认为是"LISP is a dream language for the writer of unmaintainable code.",然后继续提供一些代码示例.这些被认为是某事,因此"几乎任何人都可以在大约一秒钟内阅读和理解lisp.".

In https://www.thc.org/root/phun/unmaintain.html Lisp is regarded such that "LISP is a dream language for the writer of unmaintainable code." and then proceeds to provide some code examples. These were regarded as somthing [that] "can literally be read and understood in about a second by anyone who knows lisp." on a recent Hacker News comment.

我的问题是,作为一个只有很少的Clojure经验的人,这是什么意思?

My question is, as someone with only a very small bit of experience in Clojure — what do they mean?

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

我猜想其中某些语法的含义类似于clojure中的#(blah %)语法,对吧?

I imagine that some of this syntax means something like the #(blah %) syntax from clojure, right?

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

大部分在这里迷路了.定义一个称为:-]的函数,该函数带有一个参数<并检查是否= = 2?也许(<)是关于小于的部分函数?

Mostly lost here. Defining a function called :-] that takes an argument < and checks if it's = to 2? Perhaps (<) is a partial function regarding less than?

推荐答案

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

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.

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

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