Arrays vs tuples / lists
Tony Rogvall
tony@REDACTED
Tue May 18 22:10:52 CEST 2004
tisdagen den 18 maj 2004 kl 17.23 skrev Carsten Schultz:
> Sorry, I must have been half asleep :-)
>
> I then modify my statement that I would be worried if
> [X|_] = List
> was less efficient than
> X = head(List).
>
> Indeed I would hope both to produce exactly the same code.
>
They can not generate the SAME code, since
hd(x) will crash with badarg
and
[X|_] = x will crash with badmatch
by running erlc -S you can inspect what kind of code is generated, for
BEAM the loader
phase has to be taken into account (where Björn G has added some
transformations)
I could however not find any transformations for hd/1 and tl/1 and
assume we
have to live with the match version for best speed (if not badarg is
wanted in the crash case)
Regards
/Tony
More information about the erlang-questions
mailing list