unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* lexical binding?
@ 2021-10-24  1:09 Jean-Christophe Helary
  2021-10-24 13:32 ` Stefan Monnier
  2021-10-25 12:08 ` Michael Heerdegen
  0 siblings, 2 replies; 7+ messages in thread
From: Jean-Christophe Helary @ 2021-10-24  1:09 UTC (permalink / raw)
  To: emacs-devel

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/




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

end of thread, other threads:[~2021-10-25 22:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24  1:09 lexical binding? Jean-Christophe Helary
2021-10-24 13:32 ` Stefan Monnier
2021-10-25 12:46   ` Jean-Christophe Helary
2021-10-25 22:55     ` Stefan Monnier
2021-10-25 14:46   ` Jean-Christophe Helary
2021-10-25 17:17     ` Stefan Monnier
2021-10-25 12:08 ` Michael Heerdegen

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