From f1cb23062aa42e6d61d4ac5cf007110931072830 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Wed, 21 Oct 2015 14:26:53 -0400 Subject: [PATCH] Add examples for typed/racket/unsafe docs --- .../scribblings/reference/unsafe.scrbl | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/typed-racket-doc/typed-racket/scribblings/reference/unsafe.scrbl b/typed-racket-doc/typed-racket/scribblings/reference/unsafe.scrbl index a9649e6a..3e464f5e 100644 --- a/typed-racket-doc/typed-racket/scribblings/reference/unsafe.scrbl +++ b/typed-racket-doc/typed-racket/scribblings/reference/unsafe.scrbl @@ -1,6 +1,10 @@ #lang scribble/manual -@begin[(require (for-label (only-meta-in 0 [except-in typed/racket for])))] +@(require scribble/eval + (for-label (only-meta-in 0 [except-in typed/racket for]))) + +@(define eval (make-base-eval)) +@(eval '(require typed/racket/base)) @title{Unsafe Typed Racket operations} @@ -19,6 +23,14 @@ behavior and may even crash Typed Racket. contracts that correspond to the specified types to check that the values actually match their types. + @examples[#:eval eval + (require typed/racket/unsafe) + (code:comment "import with a bad type") + (unsafe-require/typed racket/base [values (-> String Integer)]) + (code:comment "unchecked call, the result type is wrong") + (values "foo") + ] + @history[#:added "1.3"] } @@ -30,5 +42,23 @@ behavior and may even crash Typed Racket. any contracts that correspond to the specified types. This means that uses of the exports in other modules may circumvent the type system's invariants. + @examples[#:eval eval + (module t typed/racket/base + (require typed/racket/unsafe) + (: f (-> Integer Integer)) + (define (f x) (add1 x)) + (code:comment "unsafe export, does not install checks") + (unsafe-provide f)) + + (module u racket/base + (require 't) + (code:comment "bad call that's unchecked") + (f "foo")) + + (require 'u) + ] + @history[#:added "1.3"] } + +@close-eval[eval]