Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Emacs Lisp
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===From dynamic to lexical scoping=== Like MacLisp, Emacs Lisp uses dynamic [[scope (computer science)|scope]], offering static (or lexical) as an option starting from version 24.<ref>{{cite web|title=Emacs 24.1 released|url=http://lists.gnu.org/archive/html/emacs-devel/2012-06/msg00164.html|publisher=Lists.gnu.org|access-date=2013-08-18}}</ref> It can be activated by setting the file local variable <code>lexical-binding</code>.<ref>{{cite web|url=http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00043.html |title=Lexical binding |publisher=Lists.gnu.org |date=2011-04-01 |access-date=2013-08-18}}</ref><ref>{{cite web|url=http://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding#toc8 |title=Dynamic Binding Vs Lexical Binding |publisher=EmacsWiki |date=2013-05-17 |access-date=2013-08-18}}</ref> Before this option was added, one could use the <code>lexical-let</code> macro from the (now deprecated) "cl" package to provide effective lexical scope.<ref>{{cite web |title=Obsolete Lexical Binding |url=https://www.gnu.org/software/emacs/manual/html_node/cl/Obsolete-Lexical-Binding.html |website=GNU Emacs Common Lisp Emulation |publisher=GNU Press |access-date=27 May 2021}}</ref> In dynamic scoping, if a programmer declares a variable within the scope of a function, it is available to subroutines called from within that function. Originally, this was intended as an [[Optimization (computer science)|optimization]]; lexical scoping was still uncommon and of uncertain performance. In computer scientist Olin Shivers's recollection, "I asked RMS when he was implementing emacs lisp why it was dynamically scoped and his exact reply was that lexical scope was too inefficient."<ref>{{cite web|url=http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg00650.html |title=T |publisher=People.csail.mit.edu |access-date=2013-08-18}}</ref> Dynamic scoping was also meant to provide greater flexibility for user customizations. However, dynamic scoping has several disadvantages. Firstly, it can easily lead to bugs in large programs, due to unintended interactions between variables in different functions. Secondly, accessing variables under dynamic scoping is generally slower than under lexical scoping.<ref>{{Cite book|last1=Featherston|first1=Sam|url=https://books.google.com/books?id=w4R1xtZzTFYC&q=scoping+is+generally+slower+than+under+lexical+scoping.&pg=PA39|title=Process|last2=Winkler|first2=Susanne|date=2009-06-02|publisher=Walter de Gruyter|isbn=978-3-11-021614-1|language=en}}</ref>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Emacs Lisp
(section)
Add topic