length() in guards

Richard A. O'Keefe ok@REDACTED
Tue Sep 30 05:53:28 CEST 2003


Raimo Niskanen <raimo@REDACTED> wrote:
	We have already thought of a possible optimization in the
	compiler to convert such as "length(L) > 3" to an internal
	"length_gt(L, 3)", but it was not possible without changing the
	semantics of length(L).

Oh *curse*, that's right.  Worse still, on examining the latest sources,
I see that there _are_ cases when length/1 is used to test whether something
is a proper list or not.  What a nuisance.

The observation remains:  
 - *most* of the uses of length/1 in guards could use a bounded-time
   test because they are known to be given lists;
 - *most* of the rest could be rewritten with an improvement in both
   speed and clarity.

A set of length_{lt,eq,gt,ge,ne,le}/2 guard tests, however spelled,
would be useful.




More information about the erlang-questions mailing list