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

Kevin <>
Sat May 2 00:37:16 CEST 2009

Kostis Sagonas kostis-at-cs.ntua.gr |erlang| wrote:
> 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

Maybe thats not the best example since the keysearch in the programming 
guide is slightly different from the lists one, but I can still find
plenty of examples of functions that dont return tagged values, even 
when they fail

84> lists:nth(4, [1,2,3]).
** exception error: no function clause matching lists:nth(1,[])

90> lists:min([]).    
** exception error: no function clause matching lists:min([])

Following the programming guide those could have been written

nth(N, List) -> {value, Elem} | error

min(List) -> {value, Min} | error

More information about the erlang-questions mailing list