5 ms·
Woah, emacs lisp now has lexical scoping
by carterschonwald 14y ago
Woah, emacs lisp now has lexical scoping
- intranation 14y agoIt's opt-in, otherwise most packages would break. To enable it per-file use a file-local variable: ;;; -*- lexical-binding: t -*-
- perlgeek 14y agoHow ironic. Wouldn't it make much sense to enable it per lexical scope? Or as Perl did it (18 years ago) with a new keyword, so that you can use both dynamic and lexical variables in the same file? Best of both worlds.
- m00natic 14y agoWell, there has been lexical-let in the cl package for quite a while.
- onedognight 14y agoYou can use both in the same file; you just need to declare the dynamic ones using defvar, etc. If you turn lexical-binding on blindly, the compiler will usually tell you which variables you need to mark as dynamic.
- unhammer 14y ago(eval form t) enables lexical scoping for form. http://yoo2080.wordpress.com/2011/12/31/lexical-scoping-and-dynamic-scoping-in-emacs-lisp/ http://yoo2080.wordpress.com/2011/12/31/lexical-scoping-and-... is highly recommended reading btw.
- rcthompson 14y agoIt has to be this way to remain backward-compatible. Similar to the issues Perl is going through with things like enabling strict by default (you have to request at least a certain version, I think 5.12), and distinguishing a Perl 6 file from Perl 5 one.
- conanite 14y agoYes, this is pretty radical. More info from the manual: http://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Lexical-Binding.html http://www.gnu.org/software/emacs/manual/html_node/elisp/Usi... from http://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html http://www.gnu.org/software/emacs/manual/html_node/elisp/Lex... - Such code is also much more friendly to concurrency, which we want to add to Emacs in the near future. Exciting times ahead ...
- ams6110 14y agoIndeed, will be nice when something blocking in one window doesn't lock up the whole emacs process.