Received: by 10.68.223.72 with SMTP id qs8mr41630pbc.8.1352951138318;
Wed, 14 Nov 2012 19:45:38 -0800 (PST)
Path: s9ni11213pbb.0!nntp.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!enews6
From: "WJ" <w_a_x_...@yahoo.com>
Newsgroups: comp.lang.scheme
Subject: Re: Splitting a string on a character...
Date: 15 Nov 2012 03:45:08 GMT
Organization: NewsGuy - Unlimited Usenet $19.95
Lines: 39
Message-ID: <k81og40bfg@enews6.newsguy.com>
NNTP-Posting-Host: p3a9ccbac4dada8b4b8af1cbe119456ba80c7c0558970b3eb78fdeee8d9902a08.newsdawg.com
Mime-Version: 1.0
User-Agent: XanaNews/1.18.1.6
X-Antivirus: avast! (VPS 121114-1, 11/14/2012), Outbound message
X-Antivirus-Status: Clean
X-Received-Bytes: 1907
Content-Type: text/plain; charset=iso-8859-1
Thomas F. Burdick wrote:
> Cory Spencer <cspen...@interchange.ubc.ca> writes:
>
> > Just a quickie question - is there already a Common Lisp function that
> > will split a string on a given character?
>
> No. Personally, I'm glad. All the functions that deal with sequences
> let you specify :start and :end, and we have POSITION. Which all add
> up to a more reasonable, less garbage-y way of doing things. You can
> see more of my thoughts on the matter here:
Wow! You mean that CL is so powerful that it enables one to roll
his own split function? Gee whiz! It's like a Turing Machine or
assembly language! No wonder you're glad! I wish I had a language
like that: one that makes you continually reinvent the wheel!
Harald Hanche-Olsen wrote:
> (defun split (thing sequence)
> (loop for start = 0 then (1+ end)
> for end = (position thing sequence :start start)
> collect (subseq sequence start end)
> while end))
Clojure:
user=> (clojure.string/split "eeny,meeny , miney, mo" #"[, ]+")
["eeny" "meeny" "miney" "mo"]
Say we want to stop splitting after we have 3 items:
user=> (clojure.string/split "eeny,meeny , miney, mo" #"[, ]+" 3)
["eeny" "meeny" "miney, mo"]