Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: Re: Illegal LOOP usage? Date: Wed, 18 Jun 2025 21:57:34 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: <102vcoa$3dbeg$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Wed, 18 Jun 2025 23:57:34 +0200 (CEST) Injection-Info: dont-email.me; posting-host="faeb3e276463c6d792453c53fb61f4b5"; logging-data="3583440"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xzXNPKxurQrnvVs4g882N" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:ZQtZQDcnE1eDHxcbSzcnHiBvtLM= Edi Weitz wrote: > 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? Gauche Scheme (use srfi-13) ;; string-tokenize (use srfi-14) ;; character sets (define (split-string strng :optional (separators " ,-")) (define good-chars (char-set-complement (string->char-set separators))) (string-tokenize strng good-chars)) (split-string " foo bar-baz--zoo,,sooth,,,") ===> ("foo" "bar" "baz" "zoo" "sooth") (split-string " foo bar-baz--zoo,,sooth,,," " o") ===> ("f" "bar-baz--z" ",,s" "th,,,")