[erlang-questions] The inner workings of erlang:element/2

Adam Krupicka akrupicka@REDACTED
Thu Sep 10 11:01:13 CEST 2015


Hello,

I was recently profiling some code and noticed that erlang:element/2
doesn't show up in neither eprof nor fprof. How is this possible? Is the
compiler being smart here and rewriting

X = erlang:element(3, A)

with

{_, _, X} = A?

If so, how can the compiler know the arity of the tuple - does it have
some clever trick up it's sleeve that allows it to match only on part of
the tuple, e.g.

{_, _, X | _} = A?               %% to borrow list syntax



Thanks for reading,
A. K.



More information about the erlang-questions mailing list