Added tests and documentation for Thread and Channel types.

original commit: 6b4ca4d7b05ca42527788049a8bf20e322da889d
This commit is contained in:
Vincent St-Amour 2010-06-09 11:55:59 -04:00
parent d5c72476e8
commit c689b7d3e6
2 changed files with 53 additions and 1 deletions

View File

@ -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)))))

View File

@ -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]}