[racket-dev] [Feature Request] for macro #:when clauses should bind their results if asked.

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Tue Sep 6 14:35:39 EDT 2011

When writing a natural extension to racket/base for hashes, hash-filter-map, I found that what would be the most natural way to write it would look like so:

(define (hash-filter-map f ht)
  (for/list ([(k v) (in-hash ht)]
             #:when/bind [res (f k v)])

Instead I had to write

(define (hash-filter-map f ht)
  (for/fold ([result '()])
            ([(k v) (in-hash ht)]
    (cond [(f k v) => (lambda (temp) (cons temp result))]
          [else result])))

Which is less pretty.
I'd add this myself, but the for macros are scary. Anyone familiar with this section of code willing to add this?


Posted on the dev mailing list.