[racket] Apply proc with hasheq

From: Haiwei Zhou (highfly22 at gmail.com)
Date: Tue Dec 18 02:24:57 EST 2012

Danny,

It's a really amazing function.

I wonder when keyword arguments are passed into a procedure, are those
arguments sorted by evaluator?

John,

I never use match liking this. I really should re-read match manual again.

Thanks,
Haiwei


On 18 December 2012 15:11, Danny Yoo <dyoo at hashcollision.org> wrote:

> The function I provided for hash->keyword-apply is unfortunately
> broken; I forgot that there's a requirement on the order of the
> keywords we pass to it.  Here's a revised version:
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (define (hash->keyword-apply f a-hash [rest-args '()])
>   (define-values (keys vals)
>     (for/fold ([keys '()] [vals '()])
>               ([k (sort (hash-keys a-hash) string>? #:key symbol->string)])
>       (values (cons (string->keyword (symbol->string k)) keys)
>               (cons (hash-ref a-hash k) vals))))
>   (keyword-apply f keys vals rest-args))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121218/6e2baca4/attachment.html>

Posted on the users mailing list.