如何删除双括号并只在lisp中保留嵌套列表?

时间:2016-08-22 12:18:48

标签: list lisp common-lisp nested-lists parentheses

例如,转换自:

((((7 8) (0 H 0))) (((11 12)))) 

以下内容:

((7 8) (0 H 0) (11 12))

不是(7 8 0 H 0 11 12) !! 谢谢。

2 个答案:

答案 0 :(得分:0)

0: (MYSTERIOUS ((((7 8) (0 H 0))) (((11 12))) (((A B) (C D))) ((D E F))))
  1: (MAGIC (((7 8) (0 H 0))))
    2: (MAGIC ((7 8) (0 H 0)))
      3: (MAGIC (7 8))
      3: MAGIC returned ((7 8))
      3: (MAGIC (0 H 0))
      3: MAGIC returned ((0 H 0))
    2: MAGIC returned ((7 8) (0 H 0))
  1: MAGIC returned ((7 8) (0 H 0))
  1: (MAGIC (((11 12))))
    2: (MAGIC ((11 12)))
      3: (MAGIC (11 12))
      3: MAGIC returned ((11 12))
    2: MAGIC returned ((11 12))
  1: MAGIC returned ((11 12))
  1: (MAGIC (((A B) (C D))))
    2: (MAGIC ((A B) (C D)))
      3: (MAGIC (A B))
      3: MAGIC returned ((A B))
      3: (MAGIC (C D))
      3: MAGIC returned ((C D))
    2: MAGIC returned ((A B) (C D))
  1: MAGIC returned ((A B) (C D))
  1: (MAGIC ((D E F)))
    2: (MAGIC (D E F))
    2: MAGIC returned ((D E F))
  1: MAGIC returned ((D E F))
0: MYSTERIOUS returned ((7 8) (0 H 0) (11 12) (A B) (C D) (D E F))

答案 1 :(得分:0)

如果嵌套级别是常量,就像在示例中一样,您可以简单地执行此操作:

CL-USER> (mapcan #'car '((((7 8) (0 H 0))) (((11 12)))))
((7 8) (0 H 0) (11 12))