문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top