Arc Forumnew | comments | leaders | submitlogin
Dynamically scoped variables in lib/dynvars.arc on anarki (github.com)
2 points by rntz 5892 days ago | 1 comment


1 point by rntz 5892 days ago | link

Code very similar to this was posted on this forum before, I think by almkglor, but I don't think it made its way to anarki. I'm using it and I think it's quite useful, so I put it there. Use is pretty self-explanatory:

    (set foo 'global)
    (let foo 'local (eval 'foo))
    => global
    (let* foo 'local (eval 'foo))
    => local

    (set foo nil)
    (slet foo 1 (slet foo 2 (eval 'foo)))
    => (2 1)

    (dynvar input&)
    (def read1 () (read input&))
    (let* (input-stream&) "foo" (read1))
    => foo

-----