Re: [racket-dev] `string-split'

2012-04-19 Thread Eli Barzilay
An hour and a half ago, Ryan Culpepper wrote: > Instead of trying to design a 'string-split' that is both > miraculously intuitive and profoundly flexible, why not design it > like a Model-T Invalid analogy: the issue is not flexibility, it's making something that is simple (first) and useful (sec

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
> > (TL;DR: I'd suggest two functions: one (string-words str) > function that does Eli's way, and one (string-split str sep) that > does it Laurent's way). That would be a good option to me, considering that "my way" is with remaining ""s in the output list. The question remains if a string can b

Re: [racket-dev] `string-split'

2012-04-19 Thread Michael W
(TL;DR: I'd suggest two functions: one (string-words str) function that does Eli's way, and one (string-split str sep) that does it Laurent's way). 50 minutes ago, Eli Barzilay wrote: > That doesn't seem right -- with this you get > > -> (string-split " st ring") > '("" "st" "" "ring") > >

Re: [racket-dev] `string-split'

2012-04-19 Thread Ryan Culpepper
Instead of trying to design a 'string-split' that is both miraculously intuitive and profoundly flexible, why not design it like a Model-T and then write a guide/cookbook for how to use regexps to do all of the common cases that the extremely limited 'string-split' doesn't handle? I suspect th

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
> > 4. Related to Q3: what does "xy" as that argument mean exactly? > > a. #rx"[xy]" > > b. #rx"[xy]+" > > c. #rx"xy" > > d. #rx"(?:xy)+" > > > > Good question. d. would be the simplest case for newbies, but > > b. might be more useful. I think several other languages a

Re: [racket-dev] `string-split'

2012-04-19 Thread Eli Barzilay
Just now, Laurent wrote: > 1. Laurent: Does this make more sense? > > Yes, this definitely makes more sense to me. It would then treat > (string-split "aXXby" "X") just like the " " case. > > Although if you want to find the columns of a latex line like "x && > y & z" you will have the w

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
> > 4. Related to Q3: what does "xy" as that argument mean exactly? >> a. #rx"[xy]" >> b. #rx"[xy]+" >> c. #rx"xy" >> d. #rx"(?:xy)+" >> > > Good question. d. would be the simplest case for newbies, but b. might be > more useful. > It would make more sense that a string really is a string,

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
Continuing with this line, it seems that a better definition is as > follows: > > (define (string-split str [sep " "]) >(remove* '("") (regexp-split (regexp-quote (or sep " ")) str))) > > Except that the full definition could be a bit more efficient. > > Three questions: > > 1. Laurent: Does t

Re: [racket-dev] `string-split'

2012-04-19 Thread Eli Barzilay
[Meta-note: I'm not just flatly object to these, just trying to clarify the exact behavior and the possible effects on other functions.] 10 minutes ago, Laurent wrote: >   > >  (define (string-split str [sep #px"\\s+"]) >    (remove* '("") (regexp-split sep str))) > > Nearly, I meant som

Re: [racket-dev] `string-split'

2012-04-19 Thread Eli Barzilay
A few minutes ago, Laurent wrote: > > Then instead of #f one idea is to go one step further and consider > different useful cases based on input symbols like 'whitespaces, > 'non-alpha, etc. ? Or even a list of string/symbols that can be used > as a splitter. That would make a more powerful funct

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
On Thu, Apr 19, 2012 at 14:53, Matthew Flatt wrote: > At Thu, 19 Apr 2012 14:43:44 +0200, Laurent wrote: > > On Thu, Apr 19, 2012 at 14:33, Matthew Flatt wrote: > > > > > I agree with this: we should add `string-split', the one-argument case > > > should be as Eli wrote, > > > > > > About this I

Re: [racket-dev] `string-split'

2012-04-19 Thread Matthew Flatt
At Thu, 19 Apr 2012 14:43:44 +0200, Laurent wrote: > On Thu, Apr 19, 2012 at 14:33, Matthew Flatt wrote: > > > I agree with this: we should add `string-split', the one-argument case > > should be as Eli wrote, > > > About this I'm not sure, as one cannot reproduce this behavior by providing > a

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
On Thu, Apr 19, 2012 at 14:33, Matthew Flatt wrote: > I agree with this: we should add `string-split', the one-argument case > should be as Eli wrote, About this I'm not sure, as one cannot reproduce this behavior by providing an argument (or it could make the difference between string-as-not-r

Re: [racket-dev] `string-split'

2012-04-19 Thread Matthias Felleisen
I think Laurent pointed out in his initial message that beginners may be intimidated by regexps. I agree. Plus someone who isn't fluent with regexp may be more comfortable with string-split. Last but not least, a program documents itself more clearly with string-split vs regexp. On Apr 19,

Re: [racket-dev] `string-split'

2012-04-19 Thread Matthew Flatt
I agree with this: we should add `string-split', the one-argument case should be as Eli wrote, and the two-argument case should be as Laurent wrote. (Probably the optional second argument should be string-or-#f, where #f means to use #px"\\s+".) At Thu, 19 Apr 2012 14:30:31 +0200, Laurent wrote: >

Re: [racket-dev] `string-split'

2012-04-19 Thread Laurent
(define (string-split str [sep #px"\\s+"]) >(remove* '("") (regexp-split sep str))) > Nearly, I meant something more like this: (define (string-split str [splitter " "]) (regexp-split (regexp-quote splitter) str)) No regexp from the user POV, and much easier to use with little knowledge.

Re: [racket-dev] `string-split'

2012-04-19 Thread Sam Tobin-Hochstadt
On Thu, Apr 19, 2012 at 8:21 AM, Eli Barzilay wrote: > > Two hours ago, Laurent wrote: >> One string function that I often find useful in various scripting >> languages is a `string-split' (explode in php).  It can be done with >> `regexp-split', but having something more along the lines of a >> `

Re: [racket-dev] `string-split'

2012-04-19 Thread Eli Barzilay
[Changed title to talk about each one separately.] Two hours ago, Laurent wrote: > One string function that I often find useful in various scripting > languages is a `string-split' (explode in php). It can be done with > `regexp-split', but having something more along the lines of a > `string-spl