0
を使用して:- ソート私は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
という名前の)カスタム関数を使用してリストをソートする必要があります。私はsort
についてのlispのドキュメントを読んでいますが、私は事を理解できません。私の質問は、正確に私の比較機能に与えるものですか?
比較関数(この場合は>
ある)
(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)
)
完璧な答え、あなたのおかげで。あなたは私が待っていたより多くのことを指摘しました。たった1ヶ月間Lispを使用していました。 – Segmentation