[racket] hash-ref
It is for performance reasons. Specifically you can avoid creating the
procedure over and over (if you're calling hash-ref over and over).
Robby
On Sunday, July 18, 2010, Jos Koot <jos.koot at telefonica.net> wrote:
>
>
>
>
>
> (hash-ref
> a-hash a-key a-value)
> In the past
> a-value was required to be a procedure.
> Now it can
> be anything.
>
> Nice.
> Two caveats
> though.
> 1. If the
> value of a-value happens to be a procedure to be stored, it may unintentionally
> be called.
> 2. a-value
> may be an expresssion that takes much computation. This computation is repeated
> every time the hash-ref line is evaluated.
>
> Simply
> helped of course: I make it a habbit always to write or to have macros expand
> to:
> (hash-ref a-hash a-key (lambda ()
> a-value))
>
> In short, I do not well understand the reason to relax
> the contract of hash-ref and hash-ref!.
> Jos
>
>
>