First, elisp has separate bindings for variables and functions, so some dynamic scope errors are irrelevant.
Secondly, you can use setq to set variables, but a set of values ββdoes not withstand the exit from the dynamic area in which it is executed. This is not fundamentally different from lexical coverage, with the difference that with the dynamic viewing of setq in the called function, it can affect the value that you see after calling the function.
There's lexical-let , a macro that (essentially) mimics lexical bindings (I suppose it does this by strolling through the body and changing all occurrences of lexically valid variables in the gensymmed name, after all, not to mention the symbol), if you are absolutely necessary.
I would say, "write the code as usual." There are times when the dynamic nature of elisp will bite you, but I have found that in practice this is surprisingly rare.
Here is an example of what I talked about setq and dynamically related variables (recently evaluated in an adjacent buffer from scratch):
(let ((a nil)) (list (let ((a nil)) (setq a 'value) a) a)) (value nil)
Vatine Sep 24 '10 at 10:41 2010-09-24 10:41
source share