Cons Cells in Lisp Flavoured Erlang

Eric Bailey

Posted on 10 August, 2015
Tags: lfe, lisp, beam

Just as you'd expect from Erlang or another Lisp, in LFE, lists are composed of cons cells and when you use pattern matching to bind the head and tail of a singleton list, head holds the single element and tail is the empty list.

> (let ((`(,head . ,tail) '(a-single-element)))
    (lfe_io:format '"Head: ~w~nTail: ~w~n" `(,head ,tail)))
Head: a-single-element
Tail: ()

We can confirm this by checking that a cons cell of the atom a-single-element and the empty list is exactly equal to a singleton list of the same atom.

> (=:= (cons 'a-single-element '()) '(a-single-element))