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