[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trouble with lexical-binding.
From: |
Stefan Monnier |
Subject: |
Re: Trouble with lexical-binding. |
Date: |
Wed, 15 Apr 2015 10:44:04 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
> I don't think it can break code defined elsewhere : the (defvar ptr)
> form only has effect in its lexical scope, unlike the 2+ arguments
> versions where a default value is provided.
Indeed, these (defvar <shortvar>) are sufficiently common that I had to
make sure that they don't wreak havoc too often, so such `defvar' try
their best to only affect the current scope (typically: the current
file).
But if you have a file foo.el with
;;; - lexical-binding:t -*-
(defun foo (x)
(let ((ptr x))
(lambda (y) (+ ptr y))))
and a file bar.el with
;;; - lexical-binding:t -*-
(defvar ptr)
(defun bar ()
(let* ((ptr 6)
(f (foo 3)))
(message "%S" (funcall f 1))))
Then
emacs -Q --batch -l ~/tmp/foo.elc -l ~/tmp/bar.el --eval '(bar)'
and
emacs -Q --batch -l ~/tmp/foo.el -l ~/tmp/bar.el --eval '(bar)'
won't give you the same answer :-(
Stefan
Re: Trouble with lexical-binding., Stefan Monnier, 2015/04/13