mmxbass 2 Light Poster

I've been working on this basic DFS proof of concept for hours and just by reading the code I would swear on a stack of bibles that it's flawless and yet it flat out doesn't work. What the heck am I doing wrong? I'm 99% sure that the problem lies in the last few lines of the dfs function at the bottom.

(defvar *inf* 1e38)
(defvar *dists* nil)
(defvar *neighbors* nil)

(setq *dists* '((p ((j 2.5) (e 3) (u 3.5) (n 3.5)))
                (n ((p 3.5) (u 2)))
                (u ((n 2) (p 3.5) (e 1.8)))
                (e ((u 1.8) (p 3) (j 2.5)))
                (j ((e 2.5) (p 2.5) (m 3)))
                (m ((j 3) (s 2) (v 4)))
                (v ((e 3) (m 4)))
                (s ((m 2)))
                ))

(setq *neighbors* '((p (j e u n))
                (n (p u))
                (u (n p e))
                (e (u p j))
                (j (e p m))
                (m (j s v))
                (v (e m))
                (s (m))
                ))

(defun comb (res1 res2)
  (cons (+ (first res1) (first res2)) (append (rest res1) (rest res2)))
  )

(defun getd (src dest)
  (cond
   ((null *dists*) *inf*)
   (t (if (first (rest (assoc dest (first (rest (assoc src *dists*))))))
          (first (rest (assoc dest (first (rest (assoc src *dists*))))))
          0
   ))))

(defun getn (node)
  (cond
   ((null *neighbors*) nil)
   ((null (assoc node *neighbors*)) nil)
   (t (first (rest (assoc node *neighbors*))))
   ))

(defun minp (path1 path2)
  (if (< (first path1) (first path2))
      (append path1 nil)
      (append path2 nil)))

(defun dfs (dest slist nlist)
  (cond
   ((or (null nlist) (null (first nlist))) (cons *inf* nil))
   ((equal (first nlist) dest) (cons 0 (list dest)))
   (t
    (setq nghb (set-difference (getn (first nlist)) slist))
    (minp
     ;;(format t "~s" (getd (first nlist) (first nghb)))
     (comb (cons (getd (first nlist) (first nghb)) nil) (dfs dest (append slist (list (first nlist))) nghb))
     (comb (cons 0 slist) (dfs dest slist (rest nlist)))
    )
    )))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.