私は以下を定義しています:
(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? odd? number? list? even?) ancestor?)
throws 次のエラーのみに問題があるようです:following predicate is not in types: integer?
これはもちろん、私の実装で定義されています。問題は、キーと値のペアが存在することを確信していることです。それを操作できます。コードのすべての行を手動で実行ancestor
できます...これを引き起こしている可能性があることに本当に困惑しています...何か考えはありますか?