title: How is a list constructed by the Erlang VM (BEAM)?
body: <p>When I create a list in Erlang, such as in the Erlang shell:</p>
  
  <pre><code>1&gt; [1, 2].
  </code></pre>
  
  <p>From what I understand, in the vm this list will be represented as a singly linked list.</p>
  
  <p>How is this structure created by the Erlang runtime?  For example, is it constructed something like this:</p>
  
  <ol>
  <li>create a structure in memory to hold an list that terminates the list</li>
  <li>create a structure in memory to hold the item '2', and a reference to the empty list.</li>
  <li>create a structure in memory to hold the item '1', and a reference to item '2'.</li>
  </ol>
  
  <p>Am I correct in thinking the following c and erlang code is where the bulk of the work is done? </p>
  
  <ul>
  <li><a href="https://github.com/erlang/otp/blob/maint/lib/stdlib/src/lists.erl" rel="nofollow noreferrer">https://github.com/erlang/otp/blob/maint/lib/stdlib/src/lists.erl</a></li>
  <li><a href="https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_bif_lists.c" rel="nofollow noreferrer">https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_bif_lists.c</a></li>
  <li><a href="https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_term.h" rel="nofollow noreferrer">https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_term.h</a></li>
  <li><a href="https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_term.c" rel="nofollow noreferrer">https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_term.c</a></li>
  </ul>
  
  <p><code>erl_term.h</code> contains a macro <code>make_list</code> but I haven't been able to find the implementation yet...</p>