change +nan.0 and +nan.f, when viewed as contracts, to

be equal?-based contracts instead of = based contracts.

Before this change, the contract (or/c 1 2 +nan.0) was the same
contract as (or/c 1 2), because +nan.0 was the same contract as
the predicate (lambda (x) (= x +nan.0)), which is the same as
(lambda (x) #f). Now, +nan.0 and +nan.f are the only numbers
that are treated as equal?-based contracts, but this means that
(or/c 1 2 +nan.0) actually accepts +nan.0.
This commit is contained in:
Robby Findler 2015-01-23 21:55:25 -06:00
parent 778a95294c
commit cc642c3382
5 changed files with 12 additions and 4 deletions

View File

@ -56,10 +56,12 @@ ordinary Racket values that double as contracts, including
@racket[null], which are treated as contracts that recognize
themselves, using @racket[eq?], }
@item{@tech{strings} and @tech{byte strings}, which are treated as contracts
@item{@tech{strings}, @tech{byte strings}, @racket[+nan.0], and
@racket[+nan.f], which are treated as contracts
that recognize themselves using @racket[equal?], }
@item{@tech{numbers}, which are treated as contracts
@item{@tech{numbers} (except @racket[+nan.0] and
@racket[+nan.f]), which are treated as contracts
that recognize themselves using @racket[=],}
@item{@tech{regular expressions}, which are treated as contracts
@ -114,6 +116,9 @@ For more about this hierarchy, see @tech{chaperones} and
a research paper on chaperones, impersonators, and how they can be used to
implement contracts @cite{Strickland12}.
@history[#:changed "6.1.1.8" @list{Changed @racket[+nan.0] and @racket[+nan.f] to
be @racket[equal?]-based contracts.}]
@local-table-of-contents[]
@; ----------------------------------------

View File

@ -27,6 +27,7 @@
;; test =, eq?, and equal? contract random generators
(check-not-exn (λ () (test-contract-generation 0)))
(check-not-exn (λ () (test-contract-generation +nan.0)))
(check-not-exn (λ () (test-contract-generation 'x)))
(check-not-exn (λ () (test-contract-generation "x")))

View File

@ -58,6 +58,8 @@
(test-flat-contract "x" "x" 'x)
(test-flat-contract 1 1 2)
(test-flat-contract #e1 #i1.0 'x)
(test-flat-contract +nan.0 +nan.0 +nan.f)
(test-flat-contract +nan.f +nan.f +nan.0)
(test-flat-contract #rx".x." "axq" "x")
(test-flat-contract #rx#".x." #"axq" #"x")
(test-flat-contract #rx".x." #"axq" #"x")

View File

@ -251,7 +251,7 @@
`',x
x)
name))]
[(or (bytes? x) (string? x))
[(or (bytes? x) (string? x) (equal? +nan.0 x) (equal? +nan.f x))
(make-equal-contract x (if (name-default? name) x name))]
[(number? x)
(make-=-contract x (if (name-default? name) x name))]

View File

@ -85,7 +85,7 @@
[(or (boolean? konst) (char? konst) (null? konst))
(values #`(eq? #,konst #,v)
"eq?")]
[(or (string? konst) (bytes? konst))
[(or (string? konst) (bytes? konst) (equal? konst +nan.0) (equal? konst +nan.f))
(values #`(equal? #,konst #,v)
"equal?")]
[(number? konst)