[racket] hash-ref
With a sufficiently clever compiler, that could be turned into
(hash-ref hash key var) but I don't think that we have that clever a
compiler. Without the ability to pass an explicit key like that at
all, I think you'd be stuck, regardless.
Robby
On Sun, Jul 18, 2010 at 3:55 PM, Jos Koot <jos.koot at telefonica.net> wrote:
> Now consider:
>
> (let ((var ...))
> ...
> (hash-ref hash key (lambda () var))
>
> Do I understand well that this thunk is not cq cannot be compiled to a
> constant?
> When compiling the thunk, the location of var relative to the top of the
> stack is known, is it not?
> Thanks,
> Jos
>
>> -----Original Message-----
>> From: Matthew Flatt [mailto:mflatt at cs.utah.edu]
>> Sent: 18 July 2010 22:43
>> To: Jos Koot
>> Cc: 'Robby Findler'; 'plt-scheme'
>> Subject: Re: [racket] hash-ref
>>
>> 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
>
>
>