这对我有用:
(defun peculiar-transform (input-list)
(destructuring-bind (((ignore (xb) (xc) (xb)) (xa)) (xe) (xg)) input-list
`((,xb ,xc ,xb) (,xa) (,xe ,xg))))
</code>
测试:
[1]> (peculiar-transform ‘(((NIL (B) (C) (B)) (A)) (E) (G)))
((B C B) (A) (E G))
[2]> (peculiar-transform ‘(((NIL (2) (3) (2)) (1)) (5) (7)))
((2 3 2) (1) (5 7))
</code>
我已将您的变量重命名为
XA
,
XB
,…只是为了减少我们使用时的混乱
A
,
B
,…出现在输入测试用例中。
在这里,我们正在利用
destructuring-bind
直接使用您的输入模式(仅使用重命名的变量)作为如何提取元素的规范,然后我们使用反引号语法生成具有所需输出形状的模板,将提取的部分插入到正确的位置。