Reputation: 387
Using only the cons command in the Scheme Programming Language, how can one write nested lists such as
'(a b (x y (m)))?
Upvotes: 2
Views: 276
Reputation: 4479
(define a "a")
(define b "b")
(define x "x")
(define y "y")
(define m "m")
(define example (cons a (cons b (cons (cons x (cons y (cons (cons m '()) '()))) '()))))
Resultaat:
example
'("a" "b" ("x" "y" ("m")))
Upvotes: 0
Reputation: 222973
Hint: the car
of a cons cell can be a cons cell too.
More particularly, the list you have is written in long form as:
(a . (b . ((x . (y . ((m . ()) . ()))) . ())))
Upvotes: 2