On 5/19/05, Michele Simionato <[EMAIL PROTECTED]> 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


_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to