Sorting 球拍中的奇怪行为

Sorting 球拍中的奇怪行为,sorting,hashmap,racket,predicate,Sorting,Hashmap,Racket,Predicate,我有以下定义: (struct type (parent dirty) #:mutable #:transparent) (define types (make-hash)) (define (add-key predicate parent) (begin (hash-ref! types parent (type empty #t)) ;;if the parent doesn't exist, is created with no pa

我有以下定义:

    (struct type (parent dirty) #:mutable #:transparent)
    (define types (make-hash))

    (define (add-key predicate parent)
      (begin
        (hash-ref! types parent (type empty #t)) ;;if the parent doesn't exist, is created with no parent.
        (let([node (hash-ref types predicate #f)])
          (if(or (boolean? node)   ;;the node is not on the list
                 (not(equal? (type-parent node) parent))) ;;the node has a different parent
             (hash-set! types predicate (type parent #t))
             (printf "nothing to do\n")
             ))))

    (define (ancestor? predicate1 predicate2)
      (let ([node (hash-ref types predicate2 #f)])
        (cond [(false? node)(error "following predicate is not in types: " predicate2)]
              [(empty? (type-parent node)) #f]
              [(equal? (type-parent node) predicate1) #t]
              [else (ancestor? predicate1 (type-parent node))])))
它似乎工作得很好,我可以做以下事情:

    > (ancestor? integer? even?)
    #t
    > (ancestor? list? even?)
    #f
    > (ancestor? integer? odd?)
    #t
    > 
我似乎只对
sort
as
(sort'(整数?奇数?数字?列表?偶数?)祖先?
引发以下错误:
以下谓词不在类型中:integer?
当然,这是在我的实现中定义的。问题是我确信键值对存在,我可以操纵它,我可以手动运行
祖先的每一行代码。。。我真的很困惑是什么导致了这一切。。。有什么想法吗

  • 我照原样把你的代码放进了一个文件

  • 祖先?
    :添加第一行
    (displayln`(祖先?、谓词1、谓词2))
    或添加
    (跟踪祖先?
    (在
    之后(需要球拍/跟踪)

  • 这显示了在代码中被破坏的违规调用:
    (祖先?'odd?'integer?
    会导致该错误


  • (我不知道你的代码在做什么:这个想法是很容易机械地导出问题。)

    注意:如果你在查询之前对树进行线性预处理,有一个非常可爱的算法可以让你在固定时间内进行查询。请参阅:更仔细地阅读您的问题:当您说
    (排序)(整数?奇数?列表?偶数?)
    ,您的意思是
    (排序(整数?奇数?列表?偶数?)