[racket] A little improvement

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Thu May 10 17:07:33 EDT 2012

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

Posted on the users mailing list.