unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Nicolas Richard <theonewiththeevillook@yahoo.fr>
Cc: Alan Mackenzie <acm@muc.de>, emacs-devel@gnu.org
Subject: Re: Trouble with lexical-binding.
Date: Wed, 15 Apr 2015 10:44:04 -0400	[thread overview]
Message-ID: <jwvr3rllatm.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87h9shec3s.fsf@yahoo.fr> (Nicolas Richard's message of "Wed, 15 Apr 2015 15:48:39 +0200")

> 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



  reply	other threads:[~2015-04-15 14:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 22:03 Trouble with lexical-binding Alan Mackenzie
2015-04-13 22:19 ` Philipp Stephani
2015-04-14 14:03   ` Alan Mackenzie
2015-04-14 16:53     ` Stefan Monnier
2015-04-15 13:44       ` Alan Mackenzie
2015-04-15 14:34         ` Stefan Monnier
2015-04-13 22:28 ` Stefan Monnier
2015-04-15 13:48   ` Nicolas Richard
2015-04-15 14:44     ` Stefan Monnier [this message]
2015-04-16 17:34       ` Nicolas Richard
2015-04-16 18:43         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvr3rllatm.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=theonewiththeevillook@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).