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

2012-04-19 Thread Eli Barzilay
30 minutes ago, Laurent wrote:
> 
> I meant this:
> 
> (define (string-replace from str to)
>    (regexp-replace* (regexp-quote from) str (regexp-replace-quote to)))

30 minutes ago, Matthew Flatt wrote:
> 
> Surely Laurent meant
> 
>(define (string-replace str from to)
>  (regexp-replace* (regexp-quote from) str (regexp-replace-quote to)))

(Yes, that was a typo.)

If this is added, then that begs to also have something like[*]

  (define (string-index-of sub str [start 0] [end (string-length str)])
(define m (regexp-match-positions (regexp-quote sub) str start end))
(and m (caar m)))

?  If so, then what should it be called?



([*] untested, more typos possible.)

-- 
  ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
http://barzilay.org/   Maze is Life!

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


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

2012-04-19 Thread Laurent
On Thu, Apr 19, 2012 at 14:26, Eli Barzilay  wrote:

> Two hours ago, Laurent wrote:
>
> > Maybe also a `string-replace' could be useful, especially when one
> > does not want regexps and has special characters that need to be
> > quoted.
>
> Again, it's not clear how this shold look -- my guess:
>
>  (define (string-replace from str to)
>(regexp-replace* (regexp-quote from) str to))
>

I meant this:

(define (string-replace from str to)
   (regexp-replace* (regexp-quote from) str (regexp-replace-quote to)))

(string-replace "(" "(a list)" "\\1")  ; -> "\\1a list)"

Newbie-friendly (I meant regexp-quoted without the user seeing it) and easy
to use.

Laurent
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


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

2012-04-19 Thread Matthew Flatt
At Thu, 19 Apr 2012 08:26:20 -0400, Eli Barzilay wrote:
> Two hours ago, Laurent wrote:
> 
> > Maybe also a `string-replace' could be useful, especially when one
> > does not want regexps and has special characters that need to be
> > quoted.
> 
> Again, it's not clear how this shold look -- my guess:
> 
>   (define (string-replace from str to)
> (regexp-replace* (regexp-quote from) str to))
> 
> If so, then I see a weak point for this too: on one hand it does
> compose two functions, but it does nothing more than that.  Also
> "characters that need to be quoted" seem suspicious to me -- can you
> clarify?  (I see "quoting" next to something that is supposed to be
> newbie-friendly, and my alarm goes off...)

Surely Laurent meant

   (define (string-replace str from to)
 (regexp-replace* (regexp-quote from) str (regexp-replace-quote to)))

which I think is a great addition.

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


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

2012-04-19 Thread Eli Barzilay
Two hours ago, Laurent wrote:

> Maybe also a `string-replace' could be useful, especially when one
> does not want regexps and has special characters that need to be
> quoted.

Again, it's not clear how this shold look -- my guess:

  (define (string-replace from str to)
(regexp-replace* (regexp-quote from) str to))

If so, then I see a weak point for this too: on one hand it does
compose two functions, but it does nothing more than that.  Also
"characters that need to be quoted" seem suspicious to me -- can you
clarify?  (I see "quoting" next to something that is supposed to be
newbie-friendly, and my alarm goes off...)

-- 
  ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
http://barzilay.org/   Maze is Life!
_
  Racket Developers list:
  http://lists.racket-lang.org/dev