From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: emacs 24 lexical bindings question: top level lexical bindings Date: Mon, 07 Nov 2011 09:49:27 -0500 Message-ID: References: <87obwomz1q.fsf@catphive.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1332972492 11572 80.91.229.3 (28 Mar 2012 22:08:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 28 Mar 2012 22:08:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 29 00:08:11 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SD12H-0007xu-3i for geh-help-gnu-emacs@m.gmane.org; Thu, 29 Mar 2012 00:08:09 +0200 Original-Received: from localhost ([::1]:54959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCztU-0005Ps-HZ for geh-help-gnu-emacs@m.gmane.org; Wed, 28 Mar 2012 16:55:00 -0400 Original-Path: usenet.stanford.edu!postnews.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe10.iad.POSTED!00000000!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux) Cancel-Lock: sha1:rs2UOjyoWSt7NkhTKyBnBBSV7Fo= Original-Lines: 46 Original-X-Complaints-To: abuse@UsenetServer.com Original-NNTP-Posting-Date: Mon, 07 Nov 2011 14:49:27 UTC Original-Xref: usenet.stanford.edu gnu.emacs.help:189673 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:84184 Archived-At: > I have some code like this: > ;;; -*- lexical-binding: t -*- > (let ((my-var)) > (defun f1 () ...) > (defun f2 () ...)) > when compiling generates this warning: > c5-util.el:59:1:Warning: Function c5-flymake-post-command-action will ignore > its context (my-var) > and a bunch of warnings for unused lexical variables... which I actually > do use. > So my question is... what is the compiler trying to tell me? It is tell you that the function c5-flymake-post-command-action won't actually use the `my-var' like your code obviously intended. > Are top level lexical bindings not allowed? They are, but not with `defun'. I.e. it will work if you use ;;; -*- lexical-binding: t -*- (let ((my-var)) (defalias 'f1 (lambda () ...) (defalias 'f2 (lambda () ...)) > At first I thought that the compiler was transforming my setq's of my-var in f1 > and f2 into assignments to global variables... but C-h v my-var doesn't > show anything. Also, my program is working correctly, so I'm leaning > more towards the theory that these warnings themselves are bugs, and > Emacs handles top level lexical scoping correctly. I'm surprised it works correctly. In your above code, the let will create a "lexical" binding for `my-var', but uses of `my-var' within the `defun's will not refer to that lexical binding but will look for a `my-var' dynamic binding instead. This is not a feature of the new code, just a limitation due to details of how docstrings are saved (yup, it's that silly) which makes the defalias form less memory efficient. Hopefully this problem can be resolved at some point. Stefan