我仍然在理解宏,虽然我认为我理解"反引号""unquote"和"unquote splicing"的基础知识,但我认为它们只在宏中使用/有用.
但是我从Rosetta代码(日历任务)中看到了这个Common Lisp代码,
(defun month-strings (year month)
"Collect all of the strings that make up a calendar for a given
MONTH and YEAR."
`(,(date-calc:center (month-to-word month) (length *day-row*))
,*day-row*
;; We can assume that a month calendar will always fit into a 7 by 6 block
;; of values. This makes it easy to format the resulting strings.
,@ (let ((days (make-array (* 7 6) :initial-element nil)))
(loop :for i :from (date-calc:day-of-week year month 1)
:for day …Run Code Online (Sandbox Code Playgroud) 对于大量使用的命令,我想在常见的lisp(确切地说是clisp)中设置别名,例如"defun"和"lambda"等,是否可以这样做?
这实际上是这个问题的重复,但我无法评论,并且该解决方案不适用于sbcl和clisp中的defun或lambda
我不小心忘记else在下面的cond表达式中输入 ,发生了一些奇怪的事情。
(define (abs x)
(cond ((< x 0) x)
((= x 0) 0)
(+ 1 2 1001)
))
> (abs 1)
1001
>
Run Code Online (Sandbox Code Playgroud)
的结果(abs 1)不是(+ 1 2 1001)?的结果,即 1004,而是表达式参数的最后一个元素(+ 1 2 1001)。
该cond形式是
(cond (<p1>,<e1>)
(<p2>,<e2>)
(<p3>,<e3>)
...
(<pn>,<en>))
Run Code Online (Sandbox Code Playgroud)
表达式中没有谓词(+ 1 2 1001),所以我想知道该过程+是否被视为谓词,并且它是否总是评估为真,选择最后一个元素返回。是这样操作的???
有人可以解释以下表达式吗
> (+)
0
> (+ 1)
1
> (- 1)
-1
> (/ 1)
1
> (/ 2)
1/2
> (/ 3)
1/3
Run Code Online (Sandbox Code Playgroud)
如果默认参数为 1,为什么(+ 1)return 1while (/ 2)return 1/2?
不应该(+ 1)回来2吗?