From d590eee0c773af8a1c530db244f0f1ddb29e7871 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Fri, 22 May 2020 20:54:53 -0500 Subject: [PATCH] add more checking to the bst/c example --- .../scribblings/reference/contracts.scrbl | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/contracts.scrbl b/pkgs/racket-doc/scribblings/reference/contracts.scrbl index a491eb02f9..d0f5e7ff73 100644 --- a/pkgs/racket-doc/scribblings/reference/contracts.scrbl +++ b/pkgs/racket-doc/scribblings/reference/contracts.scrbl @@ -773,13 +773,26 @@ The lazy annotations ensure that this contract does not change the running time of operations that do not inspect the entire tree. -@racketblock[(struct bt (val left right)) - (define (bst/c lo hi) - (or/c #f - (struct/dc bt - [val (between/c lo hi)] - [left (val) #:lazy (bst/c lo val)] - [right (val) #:lazy (bst/c val hi)])))] + @examples[#:eval (contract-eval) #:once + (struct bt (val left right)) + (define (bst/c lo hi) + (or/c #f + (struct/dc bt + [val (between/c lo hi)] + [left (val) #:lazy (bst/c lo val)] + [right (val) #:lazy (bst/c val hi)]))) + + (define/contract not-really-a-bst + (bst/c -inf.0 +inf.0) + (bt 5 + (bt 4 + (bt 2 #f #f) + (bt 6 #f #f)) + #f)) + + (bt-right not-really-a-bst) + (bt-val (bt-left (bt-left not-really-a-bst))) + (eval:error (bt-right (bt-left not-really-a-bst)))] @history[#:changed "6.0.1.6" @elem{Added @racket[#:inv].}] }