Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search lisp哈希符号替换返回的值_Search_Graph_Lisp_Common Lisp_Allegro Cl - Fatal编程技术网

Search lisp哈希符号替换返回的值

Search lisp哈希符号替换返回的值,search,graph,lisp,common-lisp,allegro-cl,Search,Graph,Lisp,Common Lisp,Allegro Cl,我一直在尝试为图构建类似于广度优先树的结构,它包含来自给定节点的所有可能路径。我对算法没有像对突然出现的某种错误那样多的问题。以下是相关代码: (set 'my-graph '((A (B C)) (B (D E)) (C (F G)) (D (E)) (E (H)) (F (H I)) (G

我一直在尝试为图构建类似于广度优先树的结构,它包含来自给定节点的所有可能路径。我对算法没有像对突然出现的某种错误那样多的问题。以下是相关代码:

(set 'my-graph '((A (B C))
                 (B (D E))
                 (C (F G))
                 (D (E))
                 (E (H))
                 (F (H I))
                 (G (I))
                 (H (J))
                 (I (J))
                 (J ())))


(defun search-tree(graph traversed visited)
  (cond
   ((null traversed) NIL)
   (:else (let*
              ((new-visited (append visited (list (car traversed))))
               (children (add-children graph (car traversed)
                                       (append (cdr traversed) new-visited))))
            (cond
             ((null children) (list (car traversed)))
             (:else 
              (cons (car traversed)
                    (mapcar (lambda(x) (search-tree graph (list x) new-visited)) children)))
             )
            )
          )
   )
  )

;;; Selects the node to pick returned children from
(defun add-children(graph node visited)
  (cond
   ((null graph) NIL)
   ((equal (caar graph) node) (new-nodes (cadar graph) visited))
   (:else (add-children (cdr graph) node visited))
   )
  )

;;; Returns new, unvisited nodes from the children of a node
(defun new-nodes(children visited)
  (cond
   ((null children) NIL)
   ((member (car children) visited) (new-nodes (cdr children) visited))
   (:else (cons (car children) (new-nodes (cdr children) visited)))
   )
  )
函数search tree被称为(search tree my graph'(A)'),它可以正确地返回我想要的几乎所有内容,但是第一个终端节点被替换为一个#符号(应该是(J))。这里有什么问题
这是返回的值。
(A(B(D(E(H)))(E(H(J))))(C(F(H(J))(I(J))))(G(I(J))))


我已经尝试过跟踪代码,但我仍然不明白为什么(J)列表在中间递归中用一个#符号交换。

通常我猜这与此有关

此变量控制嵌套列表的打印深度。将其设置为级别的数字。更深层次的列表将替换为
#
字符


如果将其设置为
NIL
没有帮助,那么您可能还想查阅Allegro CL手册-我可以远程记住IDE也有自己的设置。

通常我会猜测它与此有关

此变量控制嵌套列表的打印深度。将其设置为级别的数字。更深层次的列表将替换为
#
字符

如果将其设置为
NIL
没有帮助,那么您可能还想查阅Allegro CL手册-我可以远程记住IDE也有自己的设置