Try/Cond

Joachim Durchholz joachim.durchholz@REDACTED
Fri Oct 24 02:03:46 CEST 2003


Joe Armstrong wrote:
> 
> When you read code like this my brain automatically wonders --
> wonder why there is no base case for the recursion - I wonder if the programmer
> forgot it (actually a type system will go though the same kind of
> reasoning as well, so it's not a bad idea to be explicit).
> 
>  If you write it like this:
> 
> 
> 	last([_|T]) -> last(T);
> 	last([H])   -> H;
> 	last([])    -> exit(emptyListsDoNotHaveLastElementYourProgramIsNuts).
> 
>  The you will at least know that the programmer had thought about it.

Besides, Haskell does it that way, too, so it can't be entirely nuts to 
have an idiom like this :-)

Regards,
Jo




More information about the erlang-questions mailing list