* Re: Why looking-at-p works?
[not found] <mailman.10182.1520323093.27995.help-gnu-emacs@gnu.org>
@ 2018-03-06 8:49 ` Emanuel Berg
2018-05-15 8:34 ` andlind
0 siblings, 1 reply; 9+ messages in thread
From: Emanuel Berg @ 2018-03-06 8:49 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski wrote:
> (defsubst looking-at-p (regexp) "\ Same as
> `looking-at' except this function does not
> change the match data." (let
> ((inhibit-changing-match-data t)) (looking-at
> regexp)))
>
> What happens is that if I make looking-at in
> the above code fail (e.g., by saying
> (looking-at-p 123)),
> inhibit-changing-match-data remains nil, even
> though there is no unwind-protect here.
> Why does it work like this?
Do you need dynamic scope for `let' to work
like that?
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Why looking-at-p works?
2018-03-06 8:49 ` Why looking-at-p works? Emanuel Berg
@ 2018-05-15 8:34 ` andlind
2018-05-15 8:49 ` tomas
0 siblings, 1 reply; 9+ messages in thread
From: andlind @ 2018-05-15 8:34 UTC (permalink / raw)
To: help-gnu-emacs
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'.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Why looking-at-p works?
2018-05-15 8:34 ` andlind
@ 2018-05-15 8:49 ` tomas
0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2018-05-15 8:49 UTC (permalink / raw)
To: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tue, May 15, 2018 at 01:34:36AM -0700, andlind@gmail.com wrote:
[...]
> 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'.
Woah. Thanks for this one!
Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlr6nv8ACgkQBcgs9XrR2kbzCgCfQLfBGq4aJ4Ydvz5iKFmgR8rz
Vo8An1S45O8j+ZjEAJG0eXXRb0EsXrS6
=Qt7a
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 9+ messages in thread
* Why looking-at-p works?
@ 2018-03-06 7:57 Marcin Borkowski
2018-03-06 18:53 ` John Mastro
0 siblings, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2018-03-06 7:57 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi all,
(defsubst looking-at-p (regexp)
"\
Same as `looking-at' except this function does not change the match data."
(let ((inhibit-changing-match-data t))
(looking-at regexp)))
What happens is that if I make looking-at in the above code fail (e.g.,
by saying (looking-at-p 123)), inhibit-changing-match-data remains nil,
even though there is no unwind-protect here. Why does it work like
this?
TIA,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Why looking-at-p works?
2018-03-06 7:57 Marcin Borkowski
@ 2018-03-06 18:53 ` John Mastro
2018-03-06 20:42 ` Marcin Borkowski
0 siblings, 1 reply; 9+ messages in thread
From: John Mastro @ 2018-03-06 18:53 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Marcin Borkowski <mbork@mbork.pl> wrote:
> Hi all,
>
> (defsubst looking-at-p (regexp)
> "\
> Same as `looking-at' except this function does not change the match data."
> (let ((inhibit-changing-match-data t))
> (looking-at regexp)))
>
> What happens is that if I make looking-at in the above code fail (e.g.,
> by saying (looking-at-p 123)), inhibit-changing-match-data remains nil,
> even though there is no unwind-protect here. Why does it work like
> this?
If I understand your question correctly, it's nothing specific to
looking-at-p. Let-bindings are protected by a sort of implicit
unwind-protect so that they're always "un-done" upon exiting the scope,
even in case of non-local exits like an error. Otherwise errors could
leave global variables in unpredictable states.
John
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Why looking-at-p works?
2018-03-06 18:53 ` John Mastro
@ 2018-03-06 20:42 ` Marcin Borkowski
2018-03-06 22:23 ` Drew Adams
2018-03-06 23:17 ` Nick Dokos
0 siblings, 2 replies; 9+ messages in thread
From: Marcin Borkowski @ 2018-03-06 20:42 UTC (permalink / raw)
To: John Mastro; +Cc: Help Gnu Emacs mailing list
On 2018-03-06, at 19:53, John Mastro <john.b.mastro@gmail.com> wrote:
> Marcin Borkowski <mbork@mbork.pl> wrote:
>> Hi all,
>>
>> (defsubst looking-at-p (regexp)
>> "\
>> Same as `looking-at' except this function does not change the match data."
>> (let ((inhibit-changing-match-data t))
>> (looking-at regexp)))
>>
>> What happens is that if I make looking-at in the above code fail (e.g.,
>> by saying (looking-at-p 123)), inhibit-changing-match-data remains nil,
>> even though there is no unwind-protect here. Why does it work like
>> this?
>
> If I understand your question correctly, it's nothing specific to
> looking-at-p. Let-bindings are protected by a sort of implicit
> unwind-protect so that they're always "un-done" upon exiting the scope,
> even in case of non-local exits like an error. Otherwise errors could
> leave global variables in unpredictable states.
Thanks, I suspected something like that.
Where is it documented? I could find it neither in the Elisp Reference
nor in let's docstring.
TIA,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Why looking-at-p works?
2018-03-06 20:42 ` Marcin Borkowski
@ 2018-03-06 22:23 ` Drew Adams
2018-03-07 9:09 ` Marcin Borkowski
2018-03-06 23:17 ` Nick Dokos
1 sibling, 1 reply; 9+ messages in thread
From: Drew Adams @ 2018-03-06 22:23 UTC (permalink / raw)
To: Marcin Borkowski, John Mastro; +Cc: Help Gnu Emacs mailing list
> Where is it documented? I could find it neither in the Elisp
> Reference nor in let's docstring.
You might need to read a tiny bit between the lines, but this
(from (elisp) `Local Variables') pretty much suggests it:
Sometimes it is useful to give a variable a "local value"-a
value that takes effect only within a certain part of a Lisp
program.
It might have said "is in effect" instead of "takes effect".
To take another example, the 'let' special form explicitly
establishes local bindings for specific variables, which
take effect within the body of the 'let' form.
Again, "are in effect only" instead of "take effect".
(Consider suggesting a doc improvement for this point -
`M-x report-emacs-bug'. And yes, probably the doc string
should mention "_local_ variable".)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Why looking-at-p works?
2018-03-06 22:23 ` Drew Adams
@ 2018-03-07 9:09 ` Marcin Borkowski
0 siblings, 0 replies; 9+ messages in thread
From: Marcin Borkowski @ 2018-03-07 9:09 UTC (permalink / raw)
To: Drew Adams; +Cc: John Mastro, Help Gnu Emacs mailing list
On 2018-03-06, at 23:23, Drew Adams <drew.adams@oracle.com> wrote:
>> Where is it documented? I could find it neither in the Elisp
>> Reference nor in let's docstring.
>
> You might need to read a tiny bit between the lines, but this
> (from (elisp) `Local Variables') pretty much suggests it:
>
> Sometimes it is useful to give a variable a "local value"-a
> value that takes effect only within a certain part of a Lisp
> program.
>
> It might have said "is in effect" instead of "takes effect".
>
> To take another example, the 'let' special form explicitly
> establishes local bindings for specific variables, which
> take effect within the body of the 'let' form.
>
> Again, "are in effect only" instead of "take effect".
>
> (Consider suggesting a doc improvement for this point -
> `M-x report-emacs-bug'. And yes, probably the doc string
> should mention "_local_ variable".)
Thanks (to you, and also to Nick) for pointing me here. I would not
call this very explicit;-). I'll try to prepare a patch for the docs
today.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Why looking-at-p works?
2018-03-06 20:42 ` Marcin Borkowski
2018-03-06 22:23 ` Drew Adams
@ 2018-03-06 23:17 ` Nick Dokos
1 sibling, 0 replies; 9+ messages in thread
From: Nick Dokos @ 2018-03-06 23:17 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski <mbork@mbork.pl> writes:
> On 2018-03-06, at 19:53, John Mastro <john.b.mastro@gmail.com> wrote:
>
>> Marcin Borkowski <mbork@mbork.pl> wrote:
>>> Hi all,
>>>
>>> (defsubst looking-at-p (regexp)
>>> "\
>>> Same as `looking-at' except this function does not change the match data."
>>> (let ((inhibit-changing-match-data t))
>>> (looking-at regexp)))
>>>
>>> What happens is that if I make looking-at in the above code fail (e.g.,
>>> by saying (looking-at-p 123)), inhibit-changing-match-data remains nil,
>>> even though there is no unwind-protect here. Why does it work like
>>> this?
>>
>> If I understand your question correctly, it's nothing specific to
>> looking-at-p. Let-bindings are protected by a sort of implicit
>> unwind-protect so that they're always "un-done" upon exiting the scope,
>> even in case of non-local exits like an error. Otherwise errors could
>> leave global variables in unpredictable states.
>
> Thanks, I suspected something like that.
>
> Where is it documented? I could find it neither in the Elisp Reference
> nor in let's docstring.
>
(info "(elisp)Local variables")
--
Nick
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-05-15 8:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.10182.1520323093.27995.help-gnu-emacs@gnu.org>
2018-03-06 8:49 ` Why looking-at-p works? Emanuel Berg
2018-05-15 8:34 ` andlind
2018-05-15 8:49 ` tomas
2018-03-06 7:57 Marcin Borkowski
2018-03-06 18:53 ` John Mastro
2018-03-06 20:42 ` Marcin Borkowski
2018-03-06 22:23 ` Drew Adams
2018-03-07 9:09 ` Marcin Borkowski
2018-03-06 23:17 ` Nick Dokos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).