gpt4 book ai didi

loops - Lisp 帮助 |错误 : Duplicate binding in LOOP : (result)

转载 作者:太空宇宙 更新时间:2023-11-03 19:01:16 24 4
gpt4 key购买 nike

(defmethod! expand-t-setclass (pcset &optional (n 12))
:icon *PC_ICON*
:doc "
Given any member of a t-setclass, lists every member of that t-setclass.
The optional parameter N can be used to set the number of equal steps per
octave to something other than the default of 12.

Will tolerate integers out of the mod-N range in PCSET."
:initvals '((1 3 4) 12)
:indoc '("pcset or list of them"
"modulus of the pc space")
(if (listp (first pcset))
(expand-t-setclasses pcset)
(let ((t-prime (t-primeform pcset n)))
(loop with result = nil
repeat n
for x-pcset = pcset then (xpose x-pcset 1 n)
unless (member x-pcset result) collect x-pcset into result
finally return result))))


(defmethod! expand-t-setclasses (pcset &optional (n 12))
(loop for item in pcset collect (expand-t-setclass item n)))

;-----

一般来说,我对 Lisp 不太熟悉,正在尝试找出导致此错误的错误:

错误:循环中的重复绑定(bind):(结果)

最佳答案

在引入变量 RESULT 的 LOOP 中有两种形式。

WITH result = nil

COLLECT ... INTO result

以上都创建了一个变量绑定(bind)。

我会将 COLLECT 替换为将项目推送到 RESULT 列表的表单。

(loop ...
collect item into foo
...
finally (return foo))

进入

(loop with foo = nil
...
(push item foo)
...
finally (return (reverse foo)))

你有另一个错误:

FINALLY RETURN result

LOOP 语法不支持。 FINALLY 期待复合形式。

替换为:

FINALLY (return result)

RETURN 是 Common Lisp 中定义的宏。

关于loops - Lisp 帮助 |错误 : Duplicate binding in LOOP : (result),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9250908/

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