Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些返回元素列表的东西,但有时元素列表也是元素列表。
这方面的例子是:
(1 2 3 (4 5) (6 7 (8)))
我似乎无法编写一个仅将其转换为仅包含元素的列表的函数。
(1 2 3 4 5 6 7 8)
这是原始海报提出的答案,以使遇到此问题的任何人都受益:
(define (test expresssion) (cond ((empty? expresssion) null) ((not (list? expresssion)) (list expresssion)) (else (append (test (first expresssion)) (test (rest expresssion)))))) (test '(A (B (C) D) A)) ; => '(A B C D A)