[drakma-devel] Re: [Bug Report] split-string behaves different in Lispworks and SBCL. (Jianshi Huang)

Jianshi Huang jianshi.huang at gmail.com
Thu Mar 8 07:52:54 UTC 2007


> Would you like to ask on the SBCL mailing list?
>

Yes, I asked this question on #lisp and Andreas Fuchs has helped me
posting it on SBCL. One of the reply said it should be a bug in SBCL
because he gave an example showing the inconsistent behavior. Here's
the example:

Andreas Fuchs posted:

(loop for i in '(1 2 3 a 4 5 6)
     if (not (symbolp i))
        collect i into collector
     else
        do (setf collector nil)
     finally (return collector))

does not return (4 5 6), but (1 2 3 4 5 6).

And Alastair Bridgewater said:

Note using (1 2 3 a 4 5 6 b) as input will result in NIL.


> > Here's the function split-string in 0.6.0
> >
> > (10defun split-string (11string &optional (separators " ,-"))
> >   "Splits STRING into substrings separated by the characters in the
> > sequence SEPARATORS.  Empty substrings aren't collected."
> >   (12loop for 13char across 14string
>
> How did you manage to add those numbers there?

Hmm.... these are all the magic numbers added by copying from paste.lisp.org.

Here's the right one.

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


Cheers,
pebblestone



More information about the Drakma-devel mailing list