[erlang-questions] Dict size in guards

Tony Rogvall <>
Fri Feb 11 09:54:37 CET 2011


And in general guard you can use something like this:

f(L) ->
    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)
    end.

It compiles a LOT better than the corresponding pattern version.

/Tony


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
>> 
>> f(L)
>>  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.
> 
> BR,
> Ulf
> 
> Ulf Wiger, CTO, Erlang Solutions, Ltd.
> http://erlang-solutions.com
> 
> 
> 
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
> 

"Have run Make so many times I dunno what's installed anymore"



More information about the erlang-questions mailing list