I don’t even understand the first form. It seems to mean a list embedded in a list, but the output is not a list embedded in a list-- it’s just a single list.
When order is important, lists are often assembled by cons-ing new elements as heads onto the existing list in reverse order and then Enum.reverse/1 is used to restore the intended order.
A list on the BEAM is made up of cons cells. Think of a cons cell as just a 2-tuple but of the format of [left | right].
[1, 2, 3] == [1 | [2 | [3 | []]]]
tl([1 | 2]) == 2 # An 'improper list', but a perfectly valid cons cell
And yep, as @peerreynders said the ++ operator is the append 2 lists operator. Do note that is not a fast operation as it has to entirely rebuild the left list to concat them (I.E. it has to rebuild all the cons cells), which is fine if it is short.
It is not just a single list, it is a linked list.
That is why You can pattern match with [head | tail]
That is why adding to the head is faster than adding to the end
And also why ++ is slow, as mentionned above