Lisp: Accessing Data in Lists of Events

Lisp provides some primitive functions (built-in functions) that, when combined with each other, can be used to retrieve any element at any depth in a list. The acronym car, used on the IBM 7090, stands for “content of the address register” and retrieves the first element in a list:

> (car first-beat)
(0 60 1000 4 60)

The acronym cdr (“content of the decrement register”) retrieves all but the first
element in a list:

> (cdr first-beat)
((0 64 1000 3 60) (0 67 1000 2 60) (0 72 1000 1 60))

Lisp also provides mechanisms to access data located at the end of lists. The
function last will, for example, return the last element of a list in a list form:

> (last first-beat)
((0 72 1000 1 60))

Deeper levels in the list structure can be accessed by re-articulating these two
same functions in different combinations. The following code shows a possible example
of how to retrieve the first event’s attack time:

> (car (car first-beat))
0

The second event’s MIDI key number is the second element from the second list
in the list of events. It can be accessed, for example, with:

> (car (cdr (car (cdr first-beat))))
64