[erlang-questions] Dict size in guards
Fri Feb 11 09:54:37 CET 2011
And in general guard you can use something like this:
if is_list(tl(tl(tl(tl(tl(tl(tl(tl(tl(tl(tl(L)))))))))))) -> long_case(L);
is_list(tl(tl(tl(tl(tl(tl(L))))))) -> medium_case(L);
true -> short_case(L)
It compiles a LOT better than the corresponding pattern version.
On 11 feb 2011, at 09.03, Ulf Wiger wrote:
> 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.
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
"Have run Make so many times I dunno what's installed anymore"
More information about the erlang-questions