Created
November 17, 2015 22:02
-
-
Save jackfirth/b12a18063ceee4f1e055 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
| (define-syntax-rule (define-parameter-with param-expr with-id) | |
| (define-syntax-rule (with-id new-param-value-expr body ...) | |
| (parameterize ([param-expr new-param-value-expr]) | |
| body ...))) | |
| (define-syntax-rule (define-parameter-call-with param-expr call-with-id) | |
| (define (call-with-id new-param-value thunk) | |
| (parameterize ([param-expr new-param-value]) | |
| (thunk)))) | |
| (define-syntax-rule (define-parameter-auxillaries param-expr with-id call-with-id) | |
| (define-parameter-with param-expr with-id) | |
| (define-parameter-call-with param-expr call-with-id)) | |
| (define foo (make-parameter #f)) | |
| (define-parameter-auxillaries foo with-foo call-with-foo) | |
| (define-syntax define-parameter | |
| (syntax-parser | |
| [(_ name:id initial:expr) | |
| (with-derived-ids #'name | |
| ([with "with-~a"] | |
| [call-with "call-with-~a"]) | |
| #'(begin | |
| (define name (make-parameter initial)) | |
| (define-parameter-auxillaries name with call-with)))])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment