Writing flatten method in Scheme

前端 未结 3 629
滥情空心
滥情空心 2020-12-21 13:03

I have been working on the following function flatten and so far have it working for just lists. I was wondering if someone could provide me with some insight on how to get

3条回答
  •  一个人的身影
    2020-12-21 14:02

    Here's one option:

    (define (flatten x)
      (cond ((null? x) '())
            ((pair? x) (append (flatten (car x)) (flatten (cdr x))))
            (else (list x))))
    

提交回复
热议问题