Scheme: do these two lists have identical memory representations?

list, memory, representation, scheme

Solution

They're different. The first list is constructed like this, corresponding to the "B" figure:

(cons 1
      (cons (cons 2 3)
            '()))

> '(1 (2 . 3))

Whereas the second list structure is constructed like this, which corresponds to the "A" figure:

(cons 1
      (cons 2 3))

> '(1 2 . 3)

Also notice that the second one is not a proper list (meaning: a list that ends with `null`).

Problem

I'm using R5RS standart of Scheme language. Please have a look at these two objects: - `(1 (2 . 3))` - `(1 2 . 3)` Do they have the same memory representations? Like this (A): Or the first one is different? Like this (B): So... What is correct?

Original source