[racket-dev] contract problem?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Jan 14 11:41:52 EST 2013


What does this error message mean: 

> (new graph% [low-cost 10][high-cost 0])
define-values: assignment disallowed;
 cannot re-define a constant
  constant: lifted.0.2

graph% is a class with a contract

;; graphs 
(define graph/c
  (class/c
   ;; specify the interval of costs [low-cost,high-cost]
   (init-field (low-cost (and/c real? (>=/c 0)))) ;; MF: made cost non-negative 
   ;; MF: Racket's contract system is deficient here:
   (init-field (high-cost (and/c real? (>=/c 0) #;(>/c low-cost)))) 
   ;; and I want this to be interpreted as an invariant
   (nodes
    ;; the list of nodes of this graph 
    (->m (set/c node? #:cmp 'eq)))
   (edges
    ;; the list of edges of this graph 
    (->m (set/c edge? #:cmp 'equal)))
   (add-edge
    ;; adding an edge (from,to) with cost w to this graph 
    (->dm ((from node?) 
           (w (cost/c (get-field low-cost this) (get-field high-cost this)))
           (to node?))
          #:pre (triangle-condition-preserved (send this edges) from w to)
          any))
   (reverse-edges
    ;; reverse all edges in this graph, keep costs 
    (->m any))
   (join 
    ;; join the nodes of other graph to this graph 
    (->dm ((other (instanceof/c graph/c)))
          #:pre (and (set=? (set-intersect (send this nodes) (send other nodes)) (seteq))
                     (= (get-field low-cost this) (get-field low-cost other))
                     (= (get-field high-cost this) (get-field high-cost other)))
          any))
   (path? 
    ;; is there a path from f to t? 
    (->dm ((f node?) (t node?)) (result boolean?)))
   (path
    ;; (path f t) is there a path from f to t and its total cost in this graph 
    (->dm ((f node?) (t node?)) #:pre (send this path? f t)
          (values (cost real?) (p (listof edge?)))))))



Posted on the dev mailing list.