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

Re: AW: Prototypes

This page is part of the web mail archives of SRFI 43 from before July 7th, 2015. The new archives for SRFI 43 contain all messages, not just those from before July 7th, 2015.



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 ...)))

vs.

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

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

Tony