emacs-devel
[Top][All Lists]
Advanced

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

lexical binding?


From: Jean-Christophe Helary
Subject: lexical binding?
Date: Sun, 24 Oct 2021 10:09:57 +0900

I need to make sure I understand this properly.

When I "setq" variables in a defun, they are by default global, so, in the 
following code:

(defun checkDayTracker ()
  "Creates values for the new index, based on yesterday's values."
  (save-current-buffer
    (set-buffer (find-file-noselect dayTrackerPath))
    (goto-char (point-min))
    (search-forward-regexp "\\([0-9]*\\.[0-9]*\\) \\([0-9]*\\) \\([0-9]*\\) 
\\([0-9]*\\)")
    (setq timeStamp (match-string 1)
          seasonNumber (match-string 2)
          totalDays (+ 1 (string-to-number (match-string 3)))
          dayInSeason (+ 1 (string-to-number (match-string 4)))
          newTracker (format "%s %s %s %s\n" (float-time) seasonNumber 
totalDays dayInSeason))
    (goto-char (point-min))
        (insert newTracker)
        (save-buffer)
        (kill-buffer))
  (list seasonNumber totalDays dayInSeason)))   

I don't *need* to return a list with the values to expose them to other 
functions. I can just call the various variables by name directly in another 
defun.

If I wanted to have them strictly local, I'd use "let" and I would only be able 
to access them in the "let" block.

If the above is correct, is there anything else there is to know about lexical 
binding?
(I certainly do not presume that I've understood more than a very tiny portion 
of the surface of this issue so I suppose that the answer is yes, but...)

Also, in a 2018 thread that I started in December 2018, when I asked about 
using setq to create lists based on other lists, Robert Thorpe says "I've seen 
lots of beginners write programs that setq undefined symbols and now I know 
why." 
(https://lists.gnu.org/archive/html/help-gnu-emacs/2018-12/msg00025.html). What 
is the issue with using setq on undefined symbols? Can that break things 
eventually? Is that related to lexical binding?

-- 
Jean-Christophe Helary @brandelune
https://mac4translators.blogspot.com
https://sr.ht/~brandelune/omegat-as-a-book/




reply via email to

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