1

How do I create pairs of pairs in scheme. I mean representation like that:

(("x" . "y") . ("a" . "b"))

(cons (cons "x" "y") (cons "a" "b")) creates different thing (("x" . "y") "a" . "b")

Please help.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nikola
  • 890
  • 1
  • 11
  • 35
  • 1
    `(("x" . "y") "a" . "b")` and `(("x" . "y") . ("a" . "b"))` are equivalent, they are just different ways of printing it. You can always check the result with `car` and `cdr` if you want to confirm. – cwbowron Dec 02 '15 at 13:37

1 Answers1

3

Actually (("x" . "y") . ("a" . "b")) is equal to (("x" . "y") "a" . "b"), as you can see if you ask to the system:

(equal? '(("x" . "y") "a" . "b") '(("x" . "y") . ("a" . "b")))

They are printed differently since (("x" . "y") "a" . "b") is printed as an improper list. To see how you can obtain a printing like (("x" . "y") . ("a" . "b")) see for instance this answer.

Community
  • 1
  • 1
Renzo
  • 26,848
  • 5
  • 49
  • 61