[emacs-w3m:13518] Re: lexical-binding question
Michael Heerdegen <[email protected]>
| Newsgroups | gmane.emacs.w3m |
|---|---|
| Message-ID | <[email protected]> |
Michael Heerdegen <[email protected]> writes: > > ;; -*- 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)) > 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. Oh, and BTW1 as you see, lexical binding mode makes it necessary to make passing the value (of the argument of fn2 or fn2) more explicit. This improves readability (which is now bad, because when reading sources of fn2 or fn3 you see nowhere that and where the value of the argument is used at all). Because you need to do this, you get also more helpful compiler warnings (which you silenced by using `ignore'). BTW2: I've also been through this. Your confusion is normal if you were mostly using dynamically binding Lisp so far. It's worth to take a bit of time to think about what lexical binding means. While code looks roughly the same, the way of programming changes a bit. Regards, Michael.