Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Emacs Lisp
(section)
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!
==Language features== Notably, the "cl-lib" package implements a fairly large subset of [[Common Lisp]]. This package replaces an earlier "cl" package, which would overwrite existing Emacs Lisp function definitions with ones more similar to those found in Common Lisp. The "cl-lib" package, on the other hand, follows Emacs Lisp style guidelines more closely and prefixes each function and macro it defines with "cl-" (e.g., <code>cl-defun</code>, which doesn't conflict with the name of the built-in <code>defun</code>), avoiding the unexpected changes in behavior that could occur whenever the "cl" package was loaded. Emacs Lisp (unlike some other Lisp implementations) does not do [[tail-call optimization]].<ref>{{cite web |title=Appendix C Porting Common Lisp |quote=Lisp programmers will want to note that the current Emacs Lisp compiler does not optimize tail recursion |url=https://www.gnu.org/software/emacs/manual/html_node/cl/Porting-Common-Lisp.html |publisher=Gnu.org |access-date=2019-10-28}}</ref> Without this, [[tail recursion]]s can eventually lead to [[stack overflow]]. The [[apel (emacs)|apel]] library aids in writing portable Emacs Lisp code, with the help of the polysylabi platform bridge. Emacs Lisp is a [[Common Lisp#The function namespace|Lisp-2]] like Common Lisp, meaning that it has a function namespace which is separate from the namespace it uses for other variables.<ref>{{cite web|url=https://groups.google.com/forum/#!topic/learn-elisp-for-emacs/RKRDc1Qw3Bs|title=Google Groups|website=groups.google.com}}</ref> ===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>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)