在Scheme中仅使用CONS命令编写列表

时间:2013-03-28 17:20:41

标签: list scheme nested

只使用Scheme Programming Language中的cons命令,如何编写嵌套列表,如

'(a b(x y(m)))?

2 个答案:

答案 0 :(得分:2)

提示:cons小区的car也可以是cons小区。

更具体地说,您拥有的列表以长格式写成:

(a . (b . ((x . (y . ((m . ()) . ()))) . ())))

答案 1 :(得分:0)

(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")))
相关问题