Common Lisp Loop工具中的语法错误

时间:2010-02-21 06:35:57

标签: common-lisp

这拒绝编译。注释掉(setf roll行可以编译它。但是,(setf roll...本身在REPL中正确评估。

程序:

;; loop n times
; sum up number of hits over value v
(defun num-hits (n v)
  (let 
     ((roll)
       (table))
    (setq table (make-hash-table))
    ;;until i == n
    (loop for i from 1 to n
      (setf roll (rolld6))
;     (if (nilp (view_hash table))
;         (oxuassign_hash table roll 1)
;       (assign_hash table (+ 1 (view_hash table roll))))
      )
    (+ (view_hash table 5) (view_hash table 6))))

消息:

*** - LOOP: illegal syntax near (SETF ROLL (ROLLD6)) in (LOOP FOR I FROM 1 TO N (SETF ROLL (ROLLD6)))

1 个答案:

答案 0 :(得分:8)

循环宏在循环体之前需要“do”。

(loop for i from 1 to n
   (stuff)

你需要

(loop for i from 1 to n do
   (stuff))