Previously, I’ve only heard “tail” being used to refer to everything but the first element, especially in languages that are based on lists.
In Elixir, the
hd (head) and
tl (tail) functions produce this:
my_list = [1, 2, 3, 4, 5] hd(my_list) #=> 1 tl(my_list) #=> [2, 3, 4, 5]
In those list-based languages, it’s common to use recursive functions on the lists, processing the head on each loop and sending the tail into the function again until it’s empty.
As far as I can tell, the first language to use linked lists was IPL from 1956. I skimmed through the user manual but didn’t see anything there, and it doesn’t seem possible to search the document. Lisp (LISt-Processing language) was created in 1958. It uses the terms
car (head) and
cdr (tail), and the
cdr is everything but the first element.
Here’s how it works in four languages that feature linked lists: Haskell, Elixir, Erlang, Common Lisp.
I suspect that it’s probably incorrect to call the last item of a linked list the “tail”, but I’m wondering if there are some situations where it would be considered correct. Does anyone know?