[racket] Weird class/c behavior

From: Eric Dobson (endobson at cs.brown.edu)
Date: Sun Aug 29 23:25:14 EDT 2010

I am using class/c and am seeing behavior that I do not understand. I
have two different contracts, one which has an extra contract on an
unused initializer argument. The interesting behavior is that the two
different contracts blame different sides for the same error. Can
someone explain why this is?

test.rkt
#lang racket
(require "target.rkt")

(define t1
 (new target1%
  (build (lambda ()
   1))))

(define t2
 (new target2%
  (build (lambda ()
   1))))

(build-target t1)
;(build-target t2)

target.rkt

#lang racket
(define target1%/c
 (class/c
  (init
   (build (-> (listof string?)))
   )
  (build (->m (-> (listof string?))))))





(define target2%/c
 (class/c
  (init
   (build (-> (listof string?)))
   (depends any/c)
   )
  (build (->m (-> (listof string?))))))



(provide build-target)
(provide/contract
 (rename target% target1% target1%/c)
 (rename target% target2% target2%/c))


(define (build-target target)
 ((send target build)))




(define target%
 (class object%
   (super-new)
   (init ((build-init   build) (lambda () null))
         ((depends-init depends) '()))

   (define build-field   build-init)
   (define depends-field depends-init)

   (define/public-final (build) build-field)
   (define/public-final (depends) depends-field)
   ))


Posted on the users mailing list.