[racket] A little improvement

From: Eli Barzilay (eli at barzilay.org)
Date: Thu May 10 17:03:34 EDT 2012

10 minutes ago, 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?

(define (fix str)
  (string-upcase
   (regexp-replace* #rx"%" (regexp-replace* #rx" / |[ -]" str "_") "")))

?

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

Posted on the users mailing list.