Lisp Extraction Mission In Lisp style languages, a list is usually defined like this:

(list 1 2 3)


For the purposes of this challenge, all lists will only contain positive integers or other lists. We will also leave out the list keyword at the start, so the list will now look like this:

(1 2 3)


We can get the first element of a list by using car. For example:

(car (1 2 3))
==&gt; 1


And we can get the original list with the first element removed with cdr:

(cdr (1 2 3))
==&gt; (2 3)


Important: cdr will always return a list, even if that list would have a single element:

(cdr (1 2))
==&gt; (2)
(car (cdr (1 2)))
==&gt; 2


Lists can also be inside other lists:

(cdr (1 2 3 (4 5 6)))
==&gt; (2 3 (4 5 6))


Write a program that returns code that uses car and cdr to return a certain integer in a list. In the code that your program returns, you can assume that the list is stored in l, the target integer is in l somewhere, and that all the integers are unique. 

Examples:

Input: (6 1 3) 3

Output: (car (cdr (cdr l)))

Input: (4 5 (1 2 (7) 9 (10 8 14))) 8

Output: (car (cdr (car (cdr (cdr (cdr (cdr (car (cdr (cdr l))))))))))

Input: (1 12 1992) 1

Output: (car l)
Common Lisp, 99

The following 99 bytes solution is a CL version of the nice Scheme answer.



(defun g(l n &amp;optional(o'l))(if(eql n l)o(and(consp l)(or(g(car l)n`(car,o))(g(cdr l)n`(cdr,o))))))


I originally tried to make use of position and position-if, but it turned out to be not as compact as I would have liked (209 bytes):

(lambda(L x &amp;aux(p'l))(labels((f(S &amp;aux e)(cons(or(position x S)(position-if(lambda(y)(if(consp y)(setf e(f y))))S)(return-from f()))e)))(dolist(o(print(f L))p)(dotimes(i o)(setf p`(cdr,p)))(setf p`(car,p)))))


Expanded

(lambda
  (l x &amp;aux (p 'l))
  (labels ((f (s &amp;aux e)
             (cons
              (or (position x s)
                  (position-if
                   (lambda (y)
                     (if (consp y)
                         (setf e (f y))))
                   s)
                  (return-from f nil))
              e)))
    (dolist (o (print (f l)) p)
      (dotimes (i o) (setf p `(cdr ,p)))
      (setf p `(car ,p)))))


Example

(funcall *fun* '(4 5 (1 2 (7) 9 (10 8 14))) 14)


The list is quoted, but if you really want, I can use a macro. 
The returned value is[1]:

(CAR (CDR (CDR (CAR (CDR (CDR (CDR (CDR (CAR (CDR (CDR L)))))))))))


For tests, I used to generate a lambda form where l was a variable:

(LAMBDA (#:G854) (CAR (CDR (CDR (CAR (CDR (CDR (CDR (CDR (CAR (CDR (CDR #:G854))))))))))))


Calling this with the original list returns 14.



[1] (caddar (cddddr (caddr l))) would be nice too