[erlang-questions] Any wisdom to offer on "tagged return values"

Robert Virding rvirding@REDACTED
Mon May 4 23:50:31 CEST 2009


Unfortunately having the return value like this IS a bad idea in that you
can only make a simple test without using an explicit case if you know the
size of the tuple. There is no way to write a generic:

Tuple = keyfind(...)

which will accept a tuple but fail on a false. Just writing it like this and
hoping will just pass on the error. I personally feel that returning
{yes,Tuple} | no would have been better. If, of course, you always know the
size of the tuple then it is easily usable.

In the dict modules we put in two functions for just this purpose: one which
fails if a value is not found, and the other which returns tagged value
depending on whether the value is found or not.

Robert

2009/5/1 Kostis Sagonas <kostis@REDACTED>

> Kevin wrote:
> > ...
> > Ironically in the lists man page it says keysearch is deprecated in
> > favor of keyfind, which does exactly what the programming rules
> > cautions against.
> >
> > keyfind(Key, N, TupleList) -> Tuple | false
>
> There is nothing ironic or wrong here.  Tuple is a tuple, not an atom so
> the two cases cannot be confused.
>
> Kostis
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090504/8a5d13ab/attachment.htm>


More information about the erlang-questions mailing list