3 ms·
In Racket (and probably other Schemes) you can do (define foo (make-parameter "some value you want by default")) (define (do-foo) (do-something (foo)) (do-
by anaphor 7y ago
In Racket (and probably other Schemes) you can do
(define foo (make-parameter "some value you want by default"))
(define (do-foo)
(do-something (foo))
(do-foo) ; uses the regular foo
(parameterize
([foo "my injected foo])
(do-foo))
And it all just works as you would expect. `foo` gets automatically reset to the prior value when it leaves the scope of the current parameterize block. You can also nest them safely, or use them in macros, and IIRC even inside threads.