Common Lisp中我可以不被暗示任何語法錯誤評估的代碼(在SBCL)下面的代碼片段:當我嘗試評估的相應方案片斷差異詞法關閉
(let ((x 0))
(defun my-incf (y)
(setf x (+ x y)))
(defun my-decf (y)
(setf x (- x y))))
MY-DECF
CL-USER> (my-incf 1)
1
CL-USER> (my-incf 1)
2
CL-USER> (my-decf 1)
1
CL-USER> (my-decf 1)
0
代碼(在DrRacket中):
(let ((x 0))
(define (my-incf y)
(set! x (+ x y)))
(define (my-decf y)
(set! x (- x y))))
它表示語法錯誤。
begin (possibly implicit): no expression after a sequence of internal definitions in: (begin (define (my-incf y) (set! x (+ x y))) (define (my-decf y) (set! x (- x y))))
有沒有人知道爲什麼在計劃中無法做到這一點?
您需要查看DrRacket中LET的語法定義。 Common Lisp示例是有效的,但我不會在我的代碼中使用它。 –
@Reiner Joswig你爲什麼不在代碼中使用它? –
我會用CLOS代替。上面的使用使得調試變得更加困難,並且它防止了編譯器將DEFUN表單識別爲函數定義。在這裏面,DEFUN不再是頂級形式。 –