[plt-scheme] hash-has-key?

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Sat Mar 28 10:46:27 EDT 2009

On Sat, Mar 28, 2009 at 10:43 AM, Thomas Chust <chust at web.de> wrote:
>
> Hello,
>
> I think it would actually be possible to design the collection API
> such that it returns a single unambiguous "not found" value. All that
> has to be done to ensure unambiguity is wrapping up "found" values:
>
>  (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.

-- 
Carl Eastlund


Posted on the users mailing list.