[erlang-questions] Dict size in guards
Fri Feb 11 09:03:17 CET 2011
On 11 Feb 2011, at 02:02, Richard O'Keefe wrote:
> The inclusion of length/1 in guard tests has always been more than
> a bit dodgy. It's better taste to avoid it. Not least because
> if you do something like
> when length(L) > 10 -> long_case(L);
> when length(L) > 5 -> medium_case(L);
> when true -> short_case(L).
> doesn't do what people often think. I've several times been
> caught by that.
Also, as pointed out by Kostis in his Tidier presentations, a fairly
common use is
f(L) when length(L) == 0 -> …
which of course has to traverse the whole (potentially very long) list.
Ulf Wiger, CTO, Erlang Solutions, Ltd.
More information about the erlang-questions