[racket] A little improvement

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu May 10 17:16:49 EDT 2012

If this is about sequencing regexp's listen to everyone else who replied. 

If this is about sequencing a bunch of functional manipulations, try this: 

#lang racket

;; this would be in a library

(define-syntax let**
  (syntax-rules ()
    [(_ tmp body) body]
    [(_ tmp a b ... body) (let ([tmp a]) (let** tmp b ... body))]))

;; -----------------------------------------------------------------------------

(define (fix str)
  (let** tmp str
         (regexp-replace* " / " tmp "_")
         (regexp-replace* " " tmp "_")
         (regexp-replace* "%" tmp "")
         (regexp-replace* "-" tmp "_")
         (string-upcase tmp)))

(fix "this/is%a-test right?")

I have found this useful and readable in circumstances where the above is a sequence of say image manipulations where even a for/fold isn't quite right. 

-- Matthias

Posted on the users mailing list.