From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: wgreenhouse@riseup.net (W. Greenhouse) Newsgroups: gmane.emacs.help Subject: Re: Declaring a local dynamic variable? Date: Sat, 28 Sep 2013 07:21:01 +0000 Message-ID: <874n951kf6.fsf@motoko.kusanagi> References: <87zjqyyq5r.fsf@informatimago.com> <5246751B.3020204@easy-emacs.de> <878uyh1n1b.fsf@motoko.kusanagi> <52467C53.7000405@easy-emacs.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1380352904 22095 80.91.229.3 (28 Sep 2013 07:21:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 28 Sep 2013 07:21:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Sep 28 09:21:47 2013 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 1VPoqY-0005OU-0O for geh-help-gnu-emacs@m.gmane.org; Sat, 28 Sep 2013 09:21:46 +0200 Original-Received: from localhost ([::1]:39963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VPoqX-0000dX-G8 for geh-help-gnu-emacs@m.gmane.org; Sat, 28 Sep 2013 03:21:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VPoqH-0000cX-P8 for help-gnu-emacs@gnu.org; Sat, 28 Sep 2013 03:21:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VPoq7-0003bA-Ox for help-gnu-emacs@gnu.org; Sat, 28 Sep 2013 03:21:29 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:35526) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VPoq7-0003ar-Hk for help-gnu-emacs@gnu.org; Sat, 28 Sep 2013 03:21:19 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VPoq5-00052R-Ue for help-gnu-emacs@gnu.org; Sat, 28 Sep 2013 09:21:17 +0200 Original-Received: from bolobolo1.torservers.net ([96.47.226.20]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 28 Sep 2013 09:21:17 +0200 Original-Received: from wgreenhouse by bolobolo1.torservers.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 28 Sep 2013 09:21:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 49 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: bolobolo1.torservers.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:hhtoFBRicJRxW5fMGGfvQ/Ekgg0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:93688 Archived-At: Andreas Röhler writes: [...] > BTW not sure if we are speaking at the same thing, resp. if this might > be expressed by "lexical" or "dynamic" already. > > IMO it's convenient to use and change a let-bound var in downward > functions, whithout the need to hand it over via arguments etc. Just > a convenience, it saves keystrokes, a major reason for me to use > Emacs. > > Maybe "let" should already provide what "declare" does? You're right, maybe we don't quite understand each other. To reiterate: As it stands now, the byte compiler throws a warning when it sees a function refer to a variable which is neither bound inside the function (e.g. by `let', by the function's arglist, etc.) nor defined globally. Variables bound by `let' do not throw the warning. And this is not a "dynamic" vs. "lexical" problem--the variables in question are already dynamic for sure, because, not being bound inside the text of their function, they can't possibly be lexically bound! This situation is analogous to the failed call to `getx' in the example under the second paragraph of (info "(elisp) Lexical Binding"). So the warning is there for good reason. When you're using dynamic binding in your library, the warning tells you that you possibly made a typo and should check to make sure you aren't setting the wrong thing. Where you're using lexical binding, it tells you that your function which refers to variable `foo' will certainly fail to pick up the lexically bound `foo' in the calling function. Either way, it is something you probably want to know about. You are of course able to use dynamic variables to pass state around between two functions, even in a library that uses lexical-binding. The compiler's just going to complain about you doing so with, e.g., `setq' without declaring the variable first. The point is also made in (info "(elisp) Dynamic Binding Tips") that, since such "utility" dynamic variables are accessible to all of Emacs, they should be usefully named to avoid collisions with similar functions, and maybe even have a docstring. Nudging the programmer to use `defvar' or `declare' for these dynamic "utility" variables therefore seems appropriate. -- Regards, WGG