Hacker News new | ask | show | jobs
by intranation 5115 days ago
It's opt-in, otherwise most packages would break.

To enable it per-file use a file-local variable:

  ;;; -*- lexical-binding: t -*-
1 comments

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

You 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.
(eval form t) enables lexical scoping for form. http://yoo2080.wordpress.com/2011/12/31/lexical-scoping-and-... is highly recommended reading btw.
It 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.
Well, there has been lexical-let in the cl package for quite a while.