3 ms·
So, I know that elisp has historically lacked lexical scope, so setting variables without a prefix has the potential for name clashes since even a variable setq
by kagevf 3y ago
So, I know that elisp has historically lacked lexical scope, so setting variables without a prefix has the potential for name clashes since even a variable setq'd into existence inside a defun will be added to the global namespace.
I did an experiment to double check it's still true in a recent-ish emacs:
(defun my-fun ()
(setq test-123-456 'this-is-a-test))
(my-fun)
test-123-456 => this-is-a-test
There is some information in the info file under elisp about lexical binding, but you can just use let to keep variables in a lexical scope.
(defun my-other-fun ()
(let ((test-789 'this-is-another-test))
test-789))
(my-other-fun)
test-789 => *** Eval error *** Symbol’s value as variable is void: test-789