[racket] A little improvement

From: Laurent (laurent.orseau at gmail.com)
Date: Thu May 10 17:10:52 EDT 2012

I find it more appropriate in a dictionary:

(define (fix2 str)
  (for/fold ([str (string-upcase str)])
    ([(k v) (in-dict '((" / " . "_")
                       (" "   . "_")
                       ("%"   . "")
                       ("-"   . "_")))])
    (regexp-replace* k str v)))

Laurent

On Thu, May 10, 2012 at 11:07 PM, Vincent St-Amour <stamourv at ccs.neu.edu>wrote:

> Using list comprehensions:
>
> (define (fix str)
>  (for/fold ([str str])
>      ([old '(" / " " " "%" "-")]
>       [new '("_"   "_" ""  "_")])
>    (regexp-replace* old str new)))
>
> Vincent
>
>
> At Thu, 10 May 2012 15:49:26 -0500,
> Grant Rettke wrote:
> >
> > Using this to help out with a task at work
> >
> > #lang racket
> >
> > (define (fix str)
> >   (define tmp str)
> >   (set! tmp (regexp-replace* " / " tmp "_"))
> >   (set! tmp (regexp-replace* " " tmp "_"))
> >   (set! tmp (regexp-replace* "%" tmp ""))
> >   (set! tmp (regexp-replace* "-" tmp "_"))
> >   (string-upcase tmp))
> >
> > Is there a better way?
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120510/9a6520c9/attachment.html>

Posted on the users mailing list.