I need to use recursion to print out each element of a list twice.
ex. rdouble'(1 2 3)
would return (1 1 2 2 3 3)
also rdouble'(1 (2 3) 4)
would return (1 1 (2 2 3 3) 4 4)
so far I have this function
(11 (2 2 3 3) (2 3) 4 4)
How do I omit the second (2 3) while still doubling the values?
Can anyone help me fix this?
ex. rdouble'(1 2 3)
would return (1 1 2 2 3 3)
also rdouble'(1 (2 3) 4)
would return (1 1 (2 2 3 3) 4 4)
so far I have this function
(defun rdouble (struct)
(cond
((atom struct) struct)
(t (cons (rdouble (car struct)) (cons (car struct)
(rdouble (cdr struct))
)))))
this works fine for the first example but during the second example it prints(11 (2 2 3 3) (2 3) 4 4)
How do I omit the second (2 3) while still doubling the values?
Can anyone help me fix this?
Last edited by nuntius on , edited 1 time in total. Reason: add code tag