递归地将列表附加到列表中元素的前面

Recursively appending lists to the front of an element within a list

我正在尝试使用 acl2 创建一个函数 "ins",它递归地将第一个参数(一个列表)附加到第二个参数(另一个列表)中每个元素的前面,其中

(ins (something) ( (a b c) (d e f) ...))

returns

( (something a b c) (something d e f) ...)

这样调用函数

(ins '((one thing)) '( ((this is)) ((something else)) ))

会给我们

'( ((one thing) (this is)) ((one thing) (something else)) ))

我想出了一个非递归函数,它只适用于包含单个元素的 arg2 列表,检查是否为空。

(defun ins(arg1 arg2)

  (if (equal arg2 nil) '() (list(append  arg1 (first arg2))))

)

当我试图想出一些递归的东西,以便它将第一个参数附加到第二个参数列表中的所有元素时,我能做的最好的是

(defun ins (arg1 arg2)

  (cond

   ((equal arg2 nil) '())

   ((not(equal arg2 nil)) (ins (list(append  arg1 (first arg2))) (first(rest arg2)))

   )))

但无论如何我总是得到一个零,我似乎无法弄清楚为什么。因此,我什至不知道我的递归调用是否正确。我只是很难追踪非平凡的递归。

是这样的吗?

(defun ins (arg1 arg2)
  (if arg2
      (cons (append arg1 (car arg2)) 
            (ins arg1 (cdr arg2)))
      '()))