added unstable/future

This commit is contained in:
Ryan Culpepper 2011-07-18 01:25:36 -06:00
parent bb5bcf2ae1
commit 61ab93b87e
4 changed files with 44 additions and 9 deletions

View File

@ -0,0 +1,23 @@
#lang racket/base
(require racket/future
(for-syntax racket/base))
(provide for/async
for*/async)
;; Note: order of touches not guaranteed.
(define-syntaxes (for/async for*/async)
(let ()
(define ((transformer for/fold/derived-id) stx)
(syntax-case stx ()
[(_ (clause ...) . body)
(quasisyntax/loc stx
(let ([futures
(#,for/fold/derived-id #,stx ([fs null]) (clause ...)
(cons (future (lambda () . body)) fs))])
;; touches futures in original order
(let loop ([fs futures])
(cond [(pair? fs) (begin (loop (cdr fs)) (touch (car fs)))]
[else (void)]))))]))
(values (transformer #'for/fold/derived)
(transformer #'for*/fold/derived))))

View File

@ -6,7 +6,7 @@
racket/draw
racket/pretty
racket/math
racket/future
unstable/future
slideshow/pict)
;; TODO: use clipping regions to avoid computing unused pixels
@ -29,14 +29,6 @@
(exact-nonnegative-integer?)
void?)])
(define-syntax (for/async stx)
(syntax-case stx ()
[(_ (clause ...) . body)
#`(let ([fs
(for/fold/derived #,stx ([fs null]) (clause ...)
(cons (future (lambda () . body)) fs))])
(for-each touch fs))]))
;; ----
(define (blur p hbr [vbr hbr] #:auto-inset? [auto-inset? #f])

View File

@ -0,0 +1,19 @@
#lang scribble/manual
@(require "utils.rkt"
(for-label racket/base
racket/future
unstable/future))
@title[#:tag "future"]{Futures}
@unstable[@author+email["Ryan Culpepper" "ryanc@racket-lang.org"]]
@defmodule[unstable/future]
@deftogether[[
@defform[(for/async (for-clause ...) body ...+)]
@defform[(for*/async (for-clause ...) body ...+)]]]{
Like @racket[for] and @racket[for*], but each iteration of the
@racket[body] is executed in a separate @racket[future], and
the futures may be @racket[touch]ed in any order.
}

View File

@ -82,6 +82,7 @@ Keep documentation and tests up to date.
@include-section["exn.scrbl"]
@include-section["file.scrbl"]
@include-section["find.scrbl"]
@include-section["future.scrbl"]
@include-section["mutated-vars.scrbl"] ;; Finding Mutable Variables
@include-section["function.scrbl"]
@include-section["generics.scrbl"]