Hacker News new | ask | show | jobs
by rurban 2868 days ago
But this could be solved with escape analysis. Rarely do such let locals shadow outer locals, and as such don't need to be restored.
1 comments

You can’t know whether you are shadowing an outer variable. With dynamic scope:

  (defun get-x () x)
  (defun foo (let ((x 7)) (get-x)))
  (foo) ;; => 7 (not shadowing x)
  (let ((x 4)) (foo)) ;; => 7 (is shadowing x)
  (setq old-get-x #'get-x)
  (defun get-x () (let ((x 10)) (funcall old-get-x)))
  (foo) ;; => 10
Emacs Lisp has supported lexical scope in its byte code compiler as an option for eons, and is starting to make more use of that. No reason why a brand new JIT couldn't follow suit.
Ouch, you are right. So the only strategy would be to switch to lexical compilation blockwise, while fixing the remaining dynamic extent vars.
Which is more or less the strategy in the Emacs codebase - the intention is to incrementally port to lexical binding on a per-file basis. (This is seen through the annotation -- lexical-binding:t -- at the top of many .el files.)