[newbie] refactor function?
Tue Feb 1 20:26:10 CET 2005
Bengt Kleberg wrote:
> Gaspar Chilingarov wrote:
> > one question to clarify thing -- when i have function, which splits list
> > to head and tail, i always need to have separate clause for empty list
> > case, am i ?
> yes, if it is ok to get an empty list as an argument.
> if you know/expect/mandate that the argument list should always have a
> head and a tail you do not need a clause for the empty list.
The correct answer is that in _most_ cases you do need a clause for the
empty list and one for the [H|T] one, but in general it really depends
on what you want to do. For example, think of how you would write a function
that returns the last element of a list (i.e., the lists:last/1 function).
More information about the erlang-questions