[emacs-w3m:13517] Re: lexical-binding question
Michael Heerdegen <[email protected]>
| Newsgroups | gmane.emacs.w3m |
|---|---|
| Message-ID | <[email protected]> |
Katsumi Yamaoka <[email protected]> writes: > The following forms are utmost simplified model of the functions > that the above form uses: > > ;; -*- lexical-binding: t -*- > (defun fn1 () ;; simplified `w3m-w3m-expand-arguments' > (eval '`,charset)) > > (defun fn2 (charset) ;; simplified `w3m-rendering-half-dump' > (ignore charset) ;; Silence the byte compiler. > (fn1)) > > (defun fn3 (&optional charset) ;; simplified `w3m-rendering-buffer' > (fn2 charset)) CHARSET is a lexical variable in fn2 and fn3. Its scope is limited to (textual) references in those functions. The lexical binding is not visible in fn1 no matter what eval '`, tricks you try, because it's out of scope. It would only work as you expect with a dynamically bound variable. You can either make `charset' special (that can even be done locally in the function) to reuse the old code, or you rewrite that stuff so that it's really lexical binding code. Then w3m-halfdump-command-arguments would probably become a function `w3m-halfdump-get-command-arguments' that depends on an CHARSET argument, or something similar. BTW, `eval' without second argument does evaluation with dynamical scoping. But it doesn't make a difference, because the call is outside of scope anyway. Michael.