From 3628df837abb149f53a95284023a1264f919f83e Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Sun, 3 Nov 2019 09:40:50 -0500 Subject: [PATCH] doc: partially revert eb20dc44 Bring back the exists gotcha, but not the references to the `racket/exists' language. --- .../scribblings/guide/contracts/exists.scrbl | 1 + .../scribblings/guide/contracts/gotchas.scrbl | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkgs/racket-doc/scribblings/guide/contracts/exists.scrbl b/pkgs/racket-doc/scribblings/guide/contracts/exists.scrbl index f901381efe..4746e3152b 100644 --- a/pkgs/racket-doc/scribblings/guide/contracts/exists.scrbl +++ b/pkgs/racket-doc/scribblings/guide/contracts/exists.scrbl @@ -56,3 +56,4 @@ To ensure that the queue representation is abstract, we can use @racket[#:∃] i Now, if clients of the data structure try to use @racket[car] and @racket[cdr], they receive an error, rather than mucking about with the internals of the queues. +See also @ctc-link["exists-gotcha"]. diff --git a/pkgs/racket-doc/scribblings/guide/contracts/gotchas.scrbl b/pkgs/racket-doc/scribblings/guide/contracts/gotchas.scrbl index cf35eb8fd6..c507a5fb22 100644 --- a/pkgs/racket-doc/scribblings/guide/contracts/gotchas.scrbl +++ b/pkgs/racket-doc/scribblings/guide/contracts/gotchas.scrbl @@ -108,6 +108,20 @@ Moral: if two values with contracts should interact, put them in separate modules with contracts at the module boundary or use @racket[#:freevar]. +@ctc-section[#:tag "exists-gotcha"]{Exists Contracts and Predicates} + +Much like the @racket[eq?] example above, @racket[#:∃] contracts +can change the behavior of a program. + +Specifically, +the @racket[null?] predicate (and many other predicates) return @racket[#f] +for @racket[#:∃] contracts, and changing one of those contracts to @racket[any/c] +means that @racket[null?] might now return @racket[#t] instead, resulting in +arbitrarily different behavior depending on how this boolean might flow around +in the program. + +Moral: Do not use predicates on @racket[#:∃] contracts. + @ctc-section{Defining Recursive Contracts} When defining a self-referential contract, it is natural to use