[plt-scheme] hash-has-key?
2009-03-28 Carl Eastlund <carl.eastlund at gmail.com>:
> On Sat, Mar 28, 2009 at 10:43 AM, Thomas Chust <chust at web.de> wrote:
>> [...]
>> (define (my-hash-ref ht key)
>> (let/ec return
>> (cons 'found (hash-ref ht key (curry return 'not-found)))))
>>
>> With this definition of a hash lookup function 'not-found is returned
>> if and only if the hash table contains no mapping for the given key.
>>
>> Whether this design is really a good solution is another question,
>> especially in a weakly typed language.
>
> Types have nothing to do with the inconvenience here; typed or
> untyped, the result of a successful lookup has to be unwrapped here.
> [...]
Hello Carl,
in a statically typed language the compiler can automate or aid the
unwrapping process more easily. But you are right that this is more of
an indirect effect and it's also a matter of taste how much magic a
compiler should apply :-)
cu,
Thomas
--
When C++ is your hammer, every problem looks like your thumb.