[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lexical-binding question
- From: Michael Heerdegen <michael_heerdegen@xxxxxx>
- Date: Tue, 06 Aug 2019 10:47:56 +0200
- X-ml-name: emacs-w3m
- X-mail-count: 13517
- References: <firstname.lastname@example.org>
Katsumi Yamaoka <yamaoka@xxxxxxx> 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.
> (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
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.