Created
August 21, 2012 19:51
-
-
Save samth/3418762 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lang racket/base | |
| (require (for-syntax syntax/parse racket/base syntax/free-vars racket/syntax) | |
| racket/place) | |
| (define-syntax (open-place stx) | |
| (syntax-parse stx | |
| [(_ ch:id body:expr ...) | |
| (define b #'(let () body ...)) | |
| (define/with-syntax b* (local-expand b 'expression null)) | |
| (define/with-syntax (fvs ...) (free-vars #'b*)) | |
| (define/with-syntax (i ...) (for/list ([(v i) (in-indexed (syntax->list #'(fvs ...)))]) i)) | |
| (define/with-syntax (v p) (generate-temporaries '(v p))) | |
| #'(let () | |
| (define p (place ch (let* ([v (place-channel-get ch)] | |
| [fvs (vector-ref v i)] ...) | |
| b*))) | |
| (define vec (vector fvs ...)) | |
| (for ([e (in-vector vec)] | |
| [n (in-list (syntax->list (quote-syntax (fvs ...))))]) | |
| (unless (place-message-allowed? e) | |
| (raise-arguments-error 'open-place | |
| "free variable values must be allowable as place messages" | |
| (symbol->string (syntax-e n)) e))) | |
| (place-channel-put p vec) | |
| p)])) | |
| (define (f x) | |
| (open-place p (displayln x))) | |
| (module+ main | |
| (f 7) | |
| (flush-output) | |
| (sleep 2) | |
| (f f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment