Re: AW: Prototypes Tony Garnock-Jones 24 Apr 2003 09:27 UTC

bear wrote:
> On Wed, 23 Apr 2003, Michael Burschik wrote:
>>>>It might also be mentioned that the return
>>>>value is ambiguous with regard to #f, [...]
>>>Can you think of a better thing to do in this case?
>>I can think of no elegant solution. Of course, you could always return
>>both the index and the element found.
> In my hash table library there is an optional third argument
> to the lookup function.  It's the value to return in case
> you don't find something.

PLT's MzScheme does a similar thing, except passes a failure-thunk
instead of a failure-value:

   (hash-table-get htable key (lambda () #f))

This I guess also permits (raise ...) in a more direct style than
fabricating a unique failure-token and then checking for it in the caller:

   (hash-table-get htable key (lambda () (raise ...)))


   (let* ((token (cons '() '()))
          (val (hash-table-get htable key token)))
     (if (eq? val token)
         (raise ...)

I think MzScheme also lets that third parameter be optional, defaulting
to (lambda () #f), just as you suggest.