[racket] hash-ref

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Jul 18 16:42:40 EDT 2010

Actually, you're right. A `lambda' form like

 (lambda () #f)

that doesn't close over anything will compile to a constant.

There is some function-call overhead when crossing the boundary from
the run-time system back to the JIT-code world, and that was partly the
motivation for special-casing non-procedure arguments to `hash-ref'.
The biggest reason, though, was that it's more convenient to pass `#f'
than `(lambda () #f)', since a `#f' result is the most common case.

At Sun, 18 Jul 2010 22:32:21 +0200, "Jos Koot" wrote:
> Ha, that makes sense.
> I had the (apparently wrong) idea that a thunk would be compiled to a ready
> to use procedure and would be immediately available at run time.
> Thanks. Jos 
> 
> > -----Original Message-----
> > From: robby.findler at gmail.com 
> > [mailto:robby.findler at gmail.com] On Behalf Of Robby Findler
> > Sent: 18 July 2010 15:39
> > To: Jos Koot
> > Cc: plt-scheme
> > Subject: Re: [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
> > >
> > >
> > >
> 
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.