ERROR: Duplicate Binding in LOOP: (result)

Discussion of Common Lisp

ERROR: Duplicate Binding in LOOP: (result)

Postby username652719 » Sun Feb 12, 2012 10:29 am

Code: Select all
(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)
Posts: 1
Joined: Sun Feb 12, 2012 10:28 am

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

Postby Kompottkin » Mon Feb 13, 2012 2:10 am

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).)
User avatar
Posts: 94
Joined: Mon Jul 21, 2008 7:26 am
Location: München, Germany

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 8 guests