Using acl2, I am trying to create a function, "ins" that recursively appends the first argument (a list) to the front of each element in the second argument (another list), where
(ins (something) ( (a b c) (d e f) ...))
returns
( (something a b c) (something d e f) ...)
so a call to the function as such
(ins '((one thing)) '( ((this is)) ((something else)) ))
will give us
'( ((one thing) (this is)) ((one thing) (something else)) ))
I've come up with non-recursive function that only works on arg2 lists containing a single element, checking if empty.
(defun ins(arg1 arg2)
(if (equal arg2 nil) '() (list(append arg1 (first arg2))))
)
When I try to come up with something recursive, so that it appends the first argument to all elements in the list of the second argument, the best I can do is
(defun ins (arg1 arg2)
(cond
((equal arg2 nil) '())
((not(equal arg2 nil)) (ins (list(append arg1 (first arg2))) (first(rest arg2)))
)))
But I always get a nil no matter what, and I can't seem to figure out why. As such, I don't even know whether my recursive call is even correct. I just have a difficult time tracing non-trivial recursion.
Something like this?
(defun ins (arg1 arg2)
(if arg2
(cons (append arg1 (car arg2))
(ins arg1 (cdr arg2)))
'()))