In ac.scm during compilation/macroexpansion there's a variable passed around called 'env which I think is the list of lexically bound symbols for the current scope. Not sure how you'd hook into that for your purposes though.
Yeah, but env just keeps the variables around, not their values. It's used to distinguish between locals and globals when compiling down to lambda.
> (ac '(fn (x) (+ x 1)) '())
(lambda (x) (ar-funcall2 _+ x 1))
> (ac '(+ x 1) '())
(ar-funcall2 _+ _x 1)
> (ac '(+ x 1) '(x))
(ar-funcall2 _+ x 1)
So it's not quite what you'd want. Off the top of my head, you could hack ac.scm to treat
(fn (x) body)
as something like
(fn (x) (= (locals* 'x) x) body (wipe (locals* 'x)))
Since Arc does all of its local binding with fn (either directly or by macroexpansion), this would work. ac.scm won't heed Arc-side redefinitions of fn, so I can't think of a convenient vanilla Arc implementation. As for efficiency, thread safety, etc., my idea seems gross.