I believe that each syntactic occurrence of the identity function is created separately, but maybe there is a special case for that one. (You can always use 'values' if you want them to be identical.)
But I believe that only thunks are treated specially, not functions of one argument. Robby On Sun, Jul 18, 2010 at 6:48 PM, Jos Koot <jos.k...@telefonica.net> wrote: > I am not sure it is a good idea to add many almost-synonyms in a language. I > just was a little bit curious. The change is backward compatible and I have > no objections against it. > Indeed values to be inserted for missing keys often are #f or 0 or '( ). It > types nicely not having to wrap these basic constants in a thunk and to gain > efficiency for free. You only have to be aware of the fact that if the value > to be inserted is to be or might be a procedure, such as (lambda (x) x) as > the most elementary procedure when building a hash of procedures, you have > to wrap it as (lambda ( ) (lambda (x) x)). Because the latter does not > capture any variables, it may even be optimized such as to avoid multiple > construction of the identity function. > In this case I would write or have my macro or module expand to for example: > > (define (identity x) x) > (define (default) identity) > > (let loop ((...)) > ... > (hash-ref! hash key default) > ...) > > I am pretty sure that in this case the identity function is constructed once > only. > Jos > > ________________________________ > From: Neil Van Dyke [mailto:n...@neilvandyke.org] > Sent: 19 July 2010 00:22 > To: Jos Koot > Cc: 'plt-scheme' > Subject: Re: [racket] hash-ref > > Jos Koot wrote at 07/18/2010 09:26 AM: > > (hash-ref a-hash a-key a-value) > In the past a-value was required to be a procedure. > Now it can be anything. > > [...] > > > In short, I do not well understand the reason to relax the contract of > hash-ref and hash-ref!. > > This behavior seems a little on the uncomfortable side of automagical to me, > and -- although I can understand the desire to keep the short name -- I > would've preferred separate procedures for the default-thunk and > default-value variations. > > Perhaps the short-name procedure could be the automagical one, and there > could be longer-name procedures, like "hash-ref/default-thunk" and > "hash-ref/default-value", for people who prefer a little less automagic in > that regard. > > -- > http://www.neilvandyke.org/ > > _________________________________________________ > For list-related administrative tasks: > http://lists.racket-lang.org/listinfo/users > _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users