Re: Hints on recursion



Dude thats it!

Is this a possible answer?

(defun contains-subsequence (lst1 lst2)
(cond
((null lst2) t)
((null lst1) nil)
(t (cond
((eq (car lst1) (car lst2))
(contains-subsequence (cdr lst1) (cdr lst2)))
(t (contains-subsequence (cdr lst1) lst2))))))

I made a mistake and placed the lists the other way around and couldnt
understand why it was always nil. I think this is it. Let me know and
thanks for the exercise.

.



Relevant Pages

  • Re: The empty list and the end of a list
    ... takes a list (tree) as input and returns a list of all atoms. ... The embedded NIL differs from the ending NIL in its syntactic ... (atom (list tree)) ... NIL atoms, rather than flattening them as if they denoted empty lists, ...
    (comp.lang.lisp)
  • Re: my first Lisp code...comments welcome
    ... If you mean false, use nil (as if it were a variable holding false, ... nils here are both as empty lists, not as falses nor as symbols. ... > (declare (fixnum n)) ... > ans) ...
    (comp.lang.lisp)
  • Re: The empty list and the end of a list
    ... takes a list (tree) as input and returns a list of all atoms. ... The embedded NIL differs from the ending NIL in its syntactic ... NIL atoms, rather than flattening them as if they denoted empty lists, ... (atom (list tree)) ...
    (comp.lang.lisp)
  • Re: NIL is not of type CONS
    ... In lisp, 'means NIL. ... Common Lisp actually has a concept of uninitialized (unbound) variables, ... It's also the case that may not help you much, because you cannot distinguish between lists and booleans here. ...
    (comp.lang.lisp)
  • Re: NIL is not of type CONS
    ... In Scheme, the empty list is ', not NIL. ... Many people around here know Scheme very well. ... The Scheme representation of lists and booleans introduces numerous ... a WIDGET class, you can pretend that there is a WIDGET* class which is ...
    (comp.lang.lisp)