[racket] A little improvement

From: Danny Yoo (dyoo at hashcollision.org)
Date: Thu May 10 17:04:27 EDT 2012

> #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))


The several uses of regexp-replace* can be simplified a little by
passing regexp-replace* a function rather than a string.  This allows
you to dynamically provide the rewrite.  For example:

;;;;;;
> (regexp-replace* "[/ %-]"
                            "this/is%a-test right?"
                            (lambda (s) (if (string=? s "%") "" "_")))
"this_isa_test_right?"
;;;;;;


Posted on the users mailing list.