[erlang-questions] List comprehension puzzler

Kenneth Lakin <>
Wed Sep 21 00:53:55 CEST 2016

On 09/20/2016 08:00 AM, Raimo Niskanen wrote:
> Note that length(ISBN) will be called twice on this maybe very long list,
> and that in itself may be bad since length/1 is O(N).

That seems easy enough to fix:

when length(I) =< 13 andalso (length(I) == 10 orelse length(I) == 13)

The assembler output indicates that length is -potentially- called three
times in this example. I guess the Erlang compiler isn't smart enough to
recognize and remove the redundant calls. OTOH, I would guess that the
perf gain for the typical Erlang program isn't worth the additional
complication in the compiler code.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160920/ae1a7072/attachment.bin>

More information about the erlang-questions mailing list