[erlang-questions] naive execution of guards

Ulf Wiger (TN/EAB) <>
Tue Dec 12 15:36:02 CET 2006

I was curious to see whether the compiler would optimize away repeated
use of the length/1 guard, e.g in the following code:

check_arity(_, L, Min, Max)
  when is_list(L), length(L) =< Min, length(L) >= Max ->

but compiling with erlc -S indicates that it doesn't:

{function, check_arity, 4, 8}.

I guess there are two reasons for doing the optimization:
- one less register to handle
- length/1 is an O(N) bif

I'm sure it's tricky, and I don't know if the above reasons are strong

Ulf W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061212/1e5b60a3/attachment.html>

More information about the erlang-questions mailing list