[erlang-questions] Erlang list equality check question
Sun Mar 25 14:04:16 CEST 2018
This sounds like a it could be compiler optimization.
However I think it would be better to have a lint tool suggesting to
rewrite that equality comparison by extracting the head and comparing only
that. Maybe code from Dialyzer could be reused to find such cases and
others, providing performance tips as well as style and maybe even
I think Erlang needs a linter. Do you guys know any such tool? Kostis has
one that rewrites calls to lists:map/2 into list comprehensions but I can’t
find it right now.
On Sat 24 Mar 2018 at 23:47, mko_io <me@REDACTED> wrote:
> Dear erlang community,
> I’ve been reading the beam book recently, just learned the memory
> representation of a list is just a con cell which occupy a machine word
> which 2 bit tag. So It’s make sense that appending a new element on a big
> list is a small operation. timer:tc/1 shows X = lists:seq(1, 10000) takes
> 1184us and X2 = [0 | X] only takes 2 us.
> But X =:= X1 takes 600us, which shows it walks the whole list to do the
> equality check, my question is why not just do a cheap con cell immediate
> comparison since erlang variables don’t vary and tl(X2) points to X1. Is
> there any method to do the cons equality comparison?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions