Scheme: do these two lists have identical memory representations?
-
13-07-2021 - |
Question
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?
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