Thanks Jon and Jen, This is a great! I figured there must be a straightforward way to do this with a `for/hash` implementation. I have not seen these 2 methods `in-hash` and `in-list` vs just using the hash or list without that sequence modifier. Can you comment on what is going on with this `in-xxx` sequence modification? The docs indicate that you get slightly better performance when using these with `for`, but its not clear why and in what situations you must use these modifiers rather than the underlying list or hash itself--is it always optional?
On Wednesday, February 20, 2019 at 5:28:06 PM UTC-5, Jon Zeppieri wrote: > > > > On Wed, Feb 20, 2019 at 5:08 PM Jon Zeppieri <[email protected] > <javascript:>> wrote: > >> >> (define (reverse-hash h) >> (for*/fold ([result (hash)]) >> ([(score letters) (in-hash h)] >> [letter (in-list letters)]) >> (hash-set result letter score))) >> >> > As with Jens's answer, we can use `for*/hash` here, as well, and make this > slightly shorter: > > (define (reverse-hash h) > (for*/hash ([(score letters) (in-hash h)] > [letter (in-list letters)]) > (values letter score))) > > `for*/hash` is really a specialized version of `for*/fold`, which handles > the hash accumulator for you. The `(values letter score)` expression in the > body indicates how the (implicit) accumulator will be updated. > > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

