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

On Wed, 23 Apr 2003, Michael Burschik wrote:

>> > It might also be mentioned that the return
>> > value is ambiguous with regard to #f, which might be a
>> > vector element that
>> > satisfied the predicate, or signal that the end of the vector was
>> > reached without satisfying the predicate.
>> 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.

So you call

  (hash-lookup htable key #f)

and if it's not in the table, it returns #f.

But if you call

  (hash-lookup htable key 'NOTFOUND)

it returns NOTFOUND.

I figured it was the right thing to do considering that no
matter what value you pick to return when something isn't
found, it could also be interpreted as the value stored under
that key.  That makes it a programmer choice instead of a
library choice; the programmer, knowing what's stored in the
table, will know what can be used safely as a meaningful
thing to return if something's not there.

I suppose you could make it optional, with a default value
of #f if you want.