This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

ERROR: Duplicate Binding in LOOP: (result)

2 posts · 2330 views

(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)))

;-----
I am not too familiar with Lisp in general, and am trying to find the bug that casues this error:

ERROR: Duplicate Binding in LOOP: (result)

Re: ERROR: Duplicate Binding in LOOP: (result)

When using collect into, you are not expected to bind the variable specified somewhere else. It will be bound by collect into. Therefore, the with result = nil clause will cause a conflict.

(Unrelated: finally return result should read finally (return result).)