This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; P07 (**) Flatten a nested list structure. | |
;; Transform a list, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively). | |
;; Example: | |
;; * (my-flatten '(a (b (c d) e))) | |
;; (A B C D E) | |
;; Hint: Use the predefined functions list and append. | |
(define (my-flatten lst) | |
(if (null? lst) | |
'() | |
(let ((head (car lst)) (flat-tail (my-flatten (cdr lst)))) | |
(append ((if (pair? head) my-flatten list) head) flat-tail)))) |
0 件のコメント:
コメントを投稿