Skip to content

Instantly share code, notes, and snippets.

@jackfirth
Created November 17, 2015 22:02
Show Gist options
  • Select an option

  • Save jackfirth/b12a18063ceee4f1e055 to your computer and use it in GitHub Desktop.

Select an option

Save jackfirth/b12a18063ceee4f1e055 to your computer and use it in GitHub Desktop.
(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