;; Debugging

(define (node-names set)
  (map bn-name set))

(define (show-bnet bnet)
  `(bnet ,(bnet-name bnet)
         nodes
         ,(map show-bn
               (vector->list (bnet-nodes bnet)))
         rec
         ,(show-rec (bnet-dissection-tree bnet))))

(define (show-bn bn)
  `(bn ,(bn-name bn)
       parents
       ,(node-names (bn-parents bn))
       children
       ,(node-names (bn-children bn))
       values
       ,(bn-value-vector bn)
       ,(if (bn-flagged bn)
          (bn-pinned-value bn)
          '*unpinned*)
       ,(bn-cdist bn)))

(define (show-rec rec)
  (if (pair? rec)
    `(rec (summation-set
           ,(node-names (summation-set rec)))
          (evaluation-set
           ,(node-names (evaluation-set rec)))
          (instantiation-set
           ,(node-names (instantiation-set rec)))
          (variable-set
           ,(node-names (variable-set rec)))
          (cache
           ,(instantiation-cache rec))
          Y
          ,(if (null? (net-y-ptr rec))
             '()
             (show-rec (net-y-ptr rec)))
          Z
          ,(if (null? (net-z-ptr rec))
             '()
             (show-rec (net-z-ptr rec))))
    `(error in rec ,rec)))