unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* PATCH: Explicitly show how let works on global-variables
@ 2022-10-04  6:46 Pedro Andres Aranda Gutierrez
  2022-10-04  7:52 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-10-04  6:46 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 584 bytes --]

Hi

this is a small patch for the 'Introduction to Emacs LISP programming'
guide to show how let works on system-wide variables.
Understanding this would have made my life easier the past +20 years ;-)
and an example is sometimes worth 100 lines of explanation (more so if you
are in a hurry and you do diagonal reading)

Best, /PA

-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #1.2: Type: text/html, Size: 912 bytes --]

[-- Attachment #2: elisp-intro.diff --]
[-- Type: text/x-patch, Size: 1211 bytes --]

diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index df8fa2f8e7..bf0ccaa301 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -3731,6 +3731,24 @@ Sample let Expression
 value of the variable @code{tiger} is printed at the location of the
 second @samp{%s}.
 
+@need 1500
+When you use a system-wide variable in @code{let}, its value is modified in its
+scope and then restored. As an example, the following snippet manipulates
+@code{system-time-locale} in the scope of the @code{let} only:
+
+@smallexample
+(setq system-time-locale "C") ;; this modifies system-time-locale system-wide
+(let ((system-time-locale "es_ES.UTF8")) ;; change it in the scope of let
+  (message "(inside let) Hoy es %s" (format-time-string "%d de %B de %Y")))
+(message "(outside) Today is %s" (format-time-string "%d %B %Y")) ;; Restore locale set before
+@end smallexample
+
+Will produce
+@smallexample
+(inside let) Hoy es 04 de octubre de 2022
+(outside) Today is 04 October 2022
+@end smallexample
+
 @node Uninitialized let Variables
 @subsection Uninitialized Variables in a @code{let} Statement
 @cindex Uninitialized @code{let} variables

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-10-06 19:34 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-04  6:46 PATCH: Explicitly show how let works on global-variables Pedro Andres Aranda Gutierrez
2022-10-04  7:52 ` Eli Zaretskii
2022-10-04  8:09   ` Pedro Andres Aranda Gutierrez
2022-10-04 11:36     ` Phil Sainty
2022-10-04 13:43       ` Stefan Monnier
2022-10-04 22:22       ` Tim Cross
2022-10-05  5:28         ` Pedro Andres Aranda Gutierrez
2022-10-06  9:00           ` Pedro Andres Aranda Gutierrez
2022-10-06 19:34             ` Emanuel Berg
2022-10-04 17:39   ` Richard Stallman
2022-10-04  7:59 ` tomas
2022-10-04 11:56   ` Phil Sainty
2022-10-04 13:48     ` Stefan Monnier
2022-10-05 21:31     ` Richard Stallman
2022-10-04 15:00 ` [External] : " Drew Adams

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).