help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why looking-at-p works?


From: address@hidden
Subject: Re: Why looking-at-p works?
Date: Tue, 15 May 2018 01:34:36 -0700 (PDT)
User-agent: G2/1.0

On Tuesday, 6 March 2018 09:50:03 UTC+1, Emanuel Berg  wrote:
> Do you need dynamic scope for `let' to work
> like that?

It depends on if the variable has been declared using `defvar' or not.

If is has beed declared with `defvar' then `let' will behave in the same way -- 
it appears as though the global variable is temporary changed in the body and 
in functions called from the body. In fact, this has been the standard way 
change a global variable in elisp for many years, and I guess no one was 
prepared to change it.

On the other hand, if the variable hasn't been declared then a statically 
scoped program will create a true local variable that doesn't affect called 
functions, whereas a dynamically scoped program would create a variable that 
would hide variables with the same name in outer scopes. (Reservation: I 
haven't verified this myself.)

Personally, I think elisp took a wrong turn when they retrofitted statically 
scopes to elisp. It would have been better to introduce a new primitive, say 
`slet', to create a static binding, regardless if the variable was global or 
not.

    -- Anders

Ps. If you use the package `lisp-font-lock-extra', variables bound e.g. by 
`let' will be highlighted, and the package will highlight local and globally 
declared variables differently. This helps you to avoid accidentally 
overwriting generically named global variables like `features' and `mode-name'.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]