Nested lists in Common Lisp really confused me. Here is the problem:
By using recursion, let (nested-list 'b '(a (b c) d))
return t
if the first argument appears in the second argument (which could be
a nested list), and nil
otherwise.
I tried find
, but it only works if the first argument is '(b c)
.
I turned my eyes on lambda expressions. I want to flatten the second
argument first, and then use eq
to compare the arguments.
(defun nested-list (x y)
(cond
((null y) ())
(t (append (lambda (flatten) (first y))
Then I got stuck. Even though I read a lot of stuff about lambda expessions, it still confused me. I do not know how to recall it when I need, I knew the funcall function, but you know I just cannot get it. I just learnt Common Lisp for 5 days, so I hope you can give me a hint. Thanks a lot!
First of all unless you mistyped if
instead of iff
the problem is quite trivial, just return t
and you're done :-)
Seriously speaking instead when you need to solve a problem using recursion the idea often is simply:
In the specific consider:
NIL
T
insteadSo basically 1 and 2 are the trivial cases; 3 and 4 are the cases in which you solve a simpler version of the problem.