Problem 3: Find It! II (100 pts)
Implement the Scheme procedure find-nest
, which takes a number n
and a symbol sym
that is bound to a nested list of numbers. It returns a Scheme expression that evaluates to n
by repeatedly applying car
and cdr
to the nested list. Assume that n
appears exactly once in the nested list bound to sym
.
(define (find-nest n sym)
'YOUR-CODE-HERE
)
;;; Tests
; scm> (define a '(1 (2 3) ((4))))
; a
; scm> (find-nest 1 'a)
; (car a)
; scm> (find-nest 2 'a)
; (car (car (cdr a)))