gpt4 book ai didi

common-lisp - Common Lisp 循环工具中的语法错误

转载 作者:行者123 更新时间:2023-12-04 03:08:22 26 4
gpt4 key购买 nike

这拒绝编译。注释掉 (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)))

最佳答案

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

(loop for i from 1 to n
(stuff)

你需要
(loop for i from 1 to n do
(stuff))

关于common-lisp - Common Lisp 循环工具中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2305092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com