title: Problem with implementing Depth First Search in Scheme
body: <p>Im trying to implement Depth First Search in Scheme, but I can only get it to partially work.
  This is my code:</p>
  
  <pre><code> (define (depth-first-search graph node neighbour path dest)
    (cond ((null? neighbour) #f)
          ((equal? node dest) path)
          ((member (car neighbour) path) (depth-first-search graph node (cdr neighbour) path dest))
          ((memq (car neighbour) (car graph)) (depth-first-search (cdr graph) (car neighbour) (memq (car neighbour) (car graph)) (append path (list (car neighbour))) dest))
          (else depth-first-search (cdr graph) path dest)))
  </code></pre>
  
  <p>And this is my graph, data structure:</p>
  
  <pre><code>  (define complete-graph
    '((a b c d e)
      (b a c)
      (c a b f)
      (d a e h)
      (e a d)
      (f c g i)
      (g f h i j) 
      (h d g j)
      (i f g j)
      (j g h i)))
  </code></pre>
  
  <p>This is how I call the procedure:</p>
  
  <pre><code>(depth-first-search complete-graph (caar complete-graph) (cdar complete-graph) (list (caar complete-graph)) 'd)
  </code></pre>
  
  <p>To procedure shoud return the full path frome the start-node to the dest(ination) as a list, but it only seems to work with some start and destination nodes. If I start with 'a and 'c, it returns the right list '(a b c), but if I try with 'a and 'd, I get #f in return. So it probably is something wrong with the backtracking in the algorithm. But I have looked at the code for too long, and I really can't find the problem..</p>