Question

I'm using R5RS standart of Scheme language.

Please have a look at these two objects:

  1. (1 (2 . 3))
  2. (1 2 . 3)

Do they have the same memory representations? Like this (A): enter image description here

Or the first one is different? Like this (B):enter image description here

So... What is correct?

Was it helpful?

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top