From c689b7d3e68c9e0d332d245ece205931bcf478a4 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Wed, 9 Jun 2010 11:55:59 -0400 Subject: [PATCH] Added tests and documentation for Thread and Channel types. original commit: 6b4ca4d7b05ca42527788049a8bf20e322da889d --- .../succeed/threads-and-channels.rkt | 50 +++++++++++++++++++ .../scribblings/ts-reference.scrbl | 4 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 collects/tests/typed-scheme/succeed/threads-and-channels.rkt diff --git a/collects/tests/typed-scheme/succeed/threads-and-channels.rkt b/collects/tests/typed-scheme/succeed/threads-and-channels.rkt new file mode 100644 index 00000000..6261363e --- /dev/null +++ b/collects/tests/typed-scheme/succeed/threads-and-channels.rkt @@ -0,0 +1,50 @@ +#lang typed/scheme + +(: chan (Channelof Symbol)) +(define chan (make-channel)) + +(define (reader) + (thread + (lambda () + (let: loop : True ((i : Integer 10)) + (if (= i 0) + #t + (begin (channel-get chan) + (loop (- i 1)))))))) + +(: writer (Symbol -> Thread)) +(define (writer x) + (thread + (lambda () + (channel-put chan x) + (channel-put chan x)))) + +(reader) +(writer 'a) +(writer 'b) +(writer 'c) +(writer 'd) +(writer 'e) + + +(define-type JumpingChannel (Rec JumpingChannel (Channelof (Pair JumpingChannel Symbol)))) +(: jump-chan JumpingChannel) +(define jump-chan (make-channel)) + +(define (jumping-reader) + (thread + (lambda () + (let: loop : True ((i : Integer 3) + (c : JumpingChannel jump-chan)) + (if (= i 0) + #t + (loop (- i 1) + (car (channel-get c)))))))) + +(jumping-reader) +(let: ((c2 : JumpingChannel (make-channel))) + (channel-put jump-chan (cons c2 'a)) + (let: ((c3 : JumpingChannel (make-channel))) + (channel-put c2 (cons c3 'b)) + (let: ((c4 : JumpingChannel (make-channel))) + (channel-put c3 (cons c4 'c))))) diff --git a/collects/typed-scheme/scribblings/ts-reference.scrbl b/collects/typed-scheme/scribblings/ts-reference.scrbl index da763578..a341bffe 100644 --- a/collects/typed-scheme/scribblings/ts-reference.scrbl +++ b/collects/typed-scheme/scribblings/ts-reference.scrbl @@ -48,7 +48,8 @@ @defidform[Namespace] @defidform[EOF] @defidform[Continuation-Mark-Set] -@defidform[Char])]{ +@defidform[Char] +@defidform[Thread])]{ These types represent primitive Racket data. Note that @racket[Integer] represents exact integers.} @defidform[Any]{Any Racket value. All other types are subtypes of @racket[Any].} @@ -61,6 +62,7 @@ The following base types are parameteric in their type arguments. @defform[(Listof t)]{Homogenous @rtech{lists} of @racket[t]} @defform[(Boxof t)]{A @rtech{box} of @racket[t]} +@defform[(Channelof t)]{A @rtech{channel} on which only @racket[t]s can be sent} @defform[(Syntaxof t)]{A @rtech{syntax object} containing a @racket[t]} @defform[(Vectorof t)]{Homogenous @rtech{vectors} of @racket[t]} @defform[(Option t)]{Either @racket[t] of @racket[#f]}