Illegal LOOP usage?



So, this function from Drakma

(defun split-string (string &optional (separators " ,-"))
"Splits STRING into substrings separated by the characters in the
sequence SEPARATORS. Empty substrings aren't collected."
(loop for char across string
when (find char separators :test #'char=)
when collector
collect (coerce collector 'string) into result
and do (setq collector nil) end
else
collect char into collector
finally (return (if collector
(append result (list (coerce collector 'string)))
result))))

works as intended with LispWorks, but doesn't work with AllegroCL or
SBCL. It seems the latter two simply ignore the (SETQ COLLECTOR NIL)
form. My guess is that the code above is somehow incorrect in that it
modifies a variable which is used in a "collect ... into ..." clause,
but I couldn't find anything in the CLHS that explicitly says so.

Any hints?

Thanks,
Edi.

--

Lisp is not dead, it just smells funny.

Real email: (replace (subseq "spamtrap@xxxxxxxxxx" 5) "edi")
.



Relevant Pages

  • Re: Illegal LOOP usage?
    ... "Splits STRING into substrings separated by the characters in the ... (loop for char across string ... collect (coerce collector 'string) into result ... It seems the latter two simply ignore the (SETQ COLLECTOR NIL) ...
    (comp.lang.lisp)
  • Re: Illegal LOOP usage?
    ... "Splits STRING into substrings separated by the characters in the ... (loop for char across string ... collect (coerce collector 'string) into result ... It seems the latter two simply ignore the (SETQ COLLECTOR NIL) ...
    (comp.lang.lisp)
  • Re: Working on learning lisp
    ... "Splits STRING into a list of substrings ... for char across string ... when (plusp (length collector)) ...
    (comp.lang.lisp)
  • Re: Avoiding Running Out Of Memory
    ... final String ExternalStorage = ... the widget does NOT keep a reference to the Bitmap ... why was the garbage collector being so tardy in ... Since the JVM can't track native memory, ...
    (comp.lang.java.programmer)
  • Re: VC2005 C++/CLI VB.NET byref unmanaged interop
    ... String^ str = gcnew String; ... wrap the String^, that the String^ will not be garbage collected. ... gcroot has nothing to do with causing a ref class to be garbage collected, ... with the reference on the stack the collector sees it). ...
    (microsoft.public.dotnet.languages.vc)