Nikola
Nikola

Reputation: 890

Pairs of pairs in Scheme

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.

Upvotes: 1

Views: 131

Answers (1)

Renzo
Renzo

Reputation: 27424

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.

Upvotes: 3

Related Questions