Okay, after a little prompting from Matthew I see that this is just a plain old bug in the contract system. I've pushed a fix.
Thanks! Robby On Mon, Mar 9, 2015 at 3:26 PM, Scott Moore <[email protected]> wrote: > Hi all, > > The racket program below exhibits behavior that I think is a bug. When using > define/contract (and I believe with-contract), contracts seem to get applied > to values later than expected. In particular, in the following example I > expect all uses of the variable “test” to see the wrapper added by the > contract. Instead, applications see the projection but inspecting the value > without invoking it does not. > > Thanks, > Scott > > #lang racket > > (require rackunit) > > (module test racket > (provide wrapped? (contract-out (test2 coerce-to-wrapped)) test) > > (define-values (prop:wrapped wrapped? prop-wrapped-accessor) > (make-impersonator-property 'wrapped)) > > (define (wrap value) > (let* ([wrapped (λ () (printf "Unwrapping ~a~n" value) value)]) > (impersonate-procedure > wrapped > #f > prop:wrapped > #t))) > > (define coerce-to-wrapped > (make-contract #:name "wrap" > #:projection > (λ (blame) > (λ (value) > (wrap value))))) > > (define/contract (test) > coerce-to-wrapped > 5) > > (define (test2) > 42)) > > (require 'test) > > (check-true (wrapped? test)) ; Should return true! > (check-true (wrapped? test2)) ; Should return true! > (check-equal? ((test)) 5) ; test is in fact wrapped, must invoke twice to use > the original procedure > (check-true (procedure? (test))) ; result of (test) is the unwrapped procedure > > -- > You received this message because you are subscribed to the Google Groups > "Racket Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-dev/452027A2-62FD-4D03-B700-89D04D3479A7%40fas.harvard.edu. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAL3TdOOqFrGxpMVPeOYGYzoOWnycScBXiYyW6FU9Z1S_iJs2OQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
