0
我有这个功能用Lisp:Lisp的 - 排序使用自定义函数
(defun AddtoQueue (queue method)
(cond
((eq method 'DFS) (append (growPath (car queue) (findCh (caar queue))) (cdr queue)))
((eq method 'BFS) (append (cdr queue) (growPath (car queue)(findCh (caar queue)))))
((eq method 'A) (SORT (append (cdr queue) (growPath (car queue) (findCh (caar queue)))) #'> :key #'pathLength ))
(T "not implemented")
)
)
我有排序使用自定义函数(这里命名pathLength
)的列表。我读了lisp有关sort
的文档,但我无法理解一件事。我的问题是我究竟在给我的比较功能?
比较功能:
(defun pathLength(point)
;;distance from origin point
(setq x (- (length queue) 1))
;;distance from end(manhattan distance) by subtracting the coords.
;;calc lists is adding or subtracting lists.
(setq y (calcLists (cadr (assoc (car point) coords)) (cadr (assoc terminal coords)) 'sub))
(setq y (+ (car y) (cadr y)))
;;sum of distance from start and end.
(+ x y)
)
完美答案,谢谢你。你指出了更多我等待得到的东西。只用了一个月的Lisp。 – Segmentation