chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] hash-table with missing keys


From: felix winkelmann
Subject: Re: [Chicken-users] hash-table with missing keys
Date: Thu, 19 May 2005 10:29:10 +0200

On 5/19/05, Michele Simionato <address@hidden> wrote:
> 
> You misunderstood Felix. The question is
> 
> """
> what's the rationale for
> 
> (hash-table-ref h 'non-existing-key)
> 
> returning #f instead of an error?
> """
> 
> Returning #f is ambiguous, it could mean that the key exists with value #f!
> 

It doesn't matter what is returned: any value will be ambiguous. That's
the reason why one should use (for example):

(hash-table-ref h 'non-existing-key 
   
<some-unique-value-known-to-the-application-that-created-and-uses-the-hashtable>)

to disambiguate the result:

(let ((unique (list 1)))
  (if (eq? unique (hash-table-ref ht 'non-existing-key unique))
      ...not found...
      ...found...))

Why `#f' in particular? Seems to be used most. (void) would be ok as well,
I guess, but that should normally be reserved for the implementation, since
it's not really well defined.


cheers,
felix



cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]