How to remove nested parentheses in LISP

前端 未结 12 1544
清酒与你
清酒与你 2020-11-29 10:20

How can I remove nested parentheses recursively in Common LISP Such as

  (unnest \'(a b c (d e) ((f) g))) => (a b c d e f g)
  (unnest \'(a b))                    


        
12条回答
  •  独厮守ぢ
    2020-11-29 10:56

    (defun flatten (l)
      (cond ((null l) nil)
            ((atom (car l)) (cons (car l) (flatten (cdr l))))
            (t (append (flatten (car l)) (flatten (cdr l))))))
    

提交回复
热议问题