Arrays vs tuples / lists
Wed May 19 09:23:43 CEST 2004
erts_debug:df(Module) can be used to disassemble a loaded
module to see what the loader has done to it. (The result will
be written to the file Module.dis.)
The hd/1 and tl/1 BIFs used to be specially optimized in early
versions of Beam, but since they are not used much in real programs,
I removed the optimizations (and optimized other things instead in
better of optimizations).
In my own code, I have sometimes used hd/1 in early drafts, but as
the code evolves, it almost always turn out that I'll need to handle
an empty list or that the data type should not be a list; therefore,
almost all hd calls disappear from my code.
Tony Rogvall <tony@REDACTED> writes:
> 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
> [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
> 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)
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions