你的榜样并不奏效。
它可以口译员工作。 但是,在汇编过程中,有一位汇编者,你看到了一种无休止的循环。
CL-USER 23 > (defun test (foo)
(sum-int-seq 5))
TEST
允许使用LspWorks口译员:
CL-USER 24 > (test :foo)
15
让我们努力汇编这一职能:
CL-USER 25 > (compile test)
Stack overflow (stack size 15997).
1 (continue) Extend stack by 50%.
2 Extend stack by 300%.
3 (abort) Return to level 0.
4 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
因此,现在的下一个问题是:它为什么以口译工作,但汇编者却无法编纂?
Okay, Ill予以解释。
首先请看口译人员。
- it sees
(sum-int-seq 5)
.
- it macroexpands it to
(COND ((EQUAL 0 5) 0) (T (+ 5 (SUM-INT-SEQ (- 5 1)))))
.
- it then evaluates above form. It determines that it needs to compute
(+ 5 (SUM-INT-SEQ (- 5 1)))
. For that it needs to macroexpand (SUM-INT-SEQ (- 5 1))
.
- eventually it will expand into something like
(cond ((EQUAL 0 (- (- (- (- (- 5 1) 1) 1) 1) 1)) 0) ...
. Which then will return 0 and the computation can use this result and add the other terms to it.
口译采用该守则,评估其能力,必要时进行宏观推广。 随后对产生的法典进行评估或宏观扩大。 因此。
现在请看汇编者。
- it sees (sum-int-seq 5) and macroexpands it into
(COND ((EQUAL 0 5) 0) (T (+ 5 (SUM-INT-SEQ (- 5 1)))))
.
- now the macroexpansion will be done on the subforms, eventually.
- the compiler will macroexpand
(SUM-INT-SEQ (- 5 1))
. note that the code never gets evaluated, only expanded.
- the compiler will macroexpand
(SUM-INT-SEQ (- (- 5 1) 1))
and so forth. finally you ll see a stack overflow.
汇编者行走(积极汇编/扩充)守则。 它可能不执行该守则(除非它确实优化或实际上对它进行明确的评估)。
如果是复健的宏观,你就不得不实际减少。 如果你在宏观范围内穿透,那么如<代码>(sum-int-seq 5)可发挥作用。 但是,关于<代码>(fun foo)(n)(sum-int-seq n),这是没有希望的,因为汇编者不知道N的价值是什么。