From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#18059: 24.3.92; defvar and special variables Date: Sun, 04 Mar 2018 18:27:54 -0500 Message-ID: <878tb72zgl.fsf@gmail.com> References: <87ha2c7lxy.fsf@web.de> <87mv0gbq33.fsf@users.sourceforge.net> <87y3k0bdm9.fsf@web.de> <87inb4bbse.fsf@users.sourceforge.net> <873727bkud.fsf@users.sourceforge.net> <87efloa000.fsf@users.sourceforge.net> <87fu5y53w5.fsf@gmail.com> <87371xlpmw.fsf@web.de> <87a7w2m1cb.fsf@web.de> <874lm7u554.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1520206037 11714 195.159.176.226 (4 Mar 2018 23:27:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 4 Mar 2018 23:27:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) Cc: 18059@debbugs.gnu.org, Stefan Monnier To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 05 00:27:13 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esd23-0001MF-RD for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Mar 2018 00:27:08 +0100 Original-Received: from localhost ([::1]:46448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esd44-000663-Md for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Mar 2018 18:29:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esd3y-00065l-FD for bug-gnu-emacs@gnu.org; Sun, 04 Mar 2018 18:29:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esd3v-0003aa-AC for bug-gnu-emacs@gnu.org; Sun, 04 Mar 2018 18:29:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36954) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1esd3v-0003aJ-4j for bug-gnu-emacs@gnu.org; Sun, 04 Mar 2018 18:29:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1esd3t-00021N-KQ for bug-gnu-emacs@gnu.org; Sun, 04 Mar 2018 18:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 04 Mar 2018 23:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18059 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18059-submit@debbugs.gnu.org id=B18059.15202060857706 (code B ref 18059); Sun, 04 Mar 2018 23:29:01 +0000 Original-Received: (at 18059) by debbugs.gnu.org; 4 Mar 2018 23:28:05 +0000 Original-Received: from localhost ([127.0.0.1]:44851 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esd2y-00020E-OJ for submit@debbugs.gnu.org; Sun, 04 Mar 2018 18:28:05 -0500 Original-Received: from mail-it0-f42.google.com ([209.85.214.42]:40404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esd2w-0001zk-VH for 18059@debbugs.gnu.org; Sun, 04 Mar 2018 18:28:03 -0500 Original-Received: by mail-it0-f42.google.com with SMTP id e64so7847057ita.5 for <18059@debbugs.gnu.org>; Sun, 04 Mar 2018 15:28:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=hjGuKwX/yB8wPeBNdcuQ7pD7939DwJz1Z5YWltmQChM=; b=LN6bRMS9CWQw9dvqAbmUHg8wCHToZGIret+FQ6FDl5I7vn48VHZ4CitxeLvQo/T1DA 7UDZHqUzW+s6mpoW1cwmhY3dKRohxc4vNV3gOtwv2lNKG0sYyjN3I9izTDXyeQcGlree D2+PGdaq8D/XwM7nYUhMmnaysh+LngJy24OdrA64dp7WZdWvL8SFoUzMWjQMeCbuduzO T4LpMyi5Cp9dRF9z5lsAT5x/upmNxtKbNuQIOcRV2fJm7l5Aux1x7Z2iGioLW+Fln8Tq nZk7owxeigK+JdiRTulmHzHkECbk34ZGI9DG2tXJWuOUmfzYg36QRHD9d/zfNBlFhYlb FNAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=hjGuKwX/yB8wPeBNdcuQ7pD7939DwJz1Z5YWltmQChM=; b=E1Y6DwwvhKjIeY3POYLYOz1gL5MKZsIXJ6V2ZpeOZXkve8H0vQ1X1fxBePk/aMs/C6 ButZwS1KVGX3ev53G+gjnOEbvhA/BqdqbJXyGq7UAeTwSKhRJJZVmp41rTnh6MNuflH9 +HT7NH8pxktQbTwFNFJsvXMHAycHOhJ/YyemDiTGGsMLsae2cTUEumAutbpC/ds3IUnw 8GW3zD7tOnQj5UjAyYrvYbzqI+nqIZ00PLfCwMKhdL5d4thuVx77+zdlVR2dmsENTYBc OUpRc821sf/ZsEK1ScMfGeww7B+szPz/EqTJkz0mnpz9viyy4e1p0thmSzpPoBP3GiXc k/QA== X-Gm-Message-State: AElRT7Fy7EfFuWqM6TFKEHY/Dgfq8kA0g1QLwm3m3Q1hPacROWx/2lR6 jZu3sWXR30Rw9/Z2no6cPWv+qQ== X-Google-Smtp-Source: AG47ELsEX0kohTvhuQLaQZW6drrriF4Su8aDhURFhTOgKVnhCRPviXVMD2ejNL8oJ57g1wC2/26Ymg== X-Received: by 10.36.13.8 with SMTP id 8mr12200892itx.42.1520206077327; Sun, 04 Mar 2018 15:27:57 -0800 (PST) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id s70sm4214903itb.0.2018.03.04.15.27.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 04 Mar 2018 15:27:55 -0800 (PST) In-Reply-To: <874lm7u554.fsf@web.de> (Michael Heerdegen's message of "Fri, 23 Feb 2018 15:55:51 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:143908 Archived-At: --=-=-= Content-Type: text/plain Michael Heerdegen writes: > Stefan Monnier writes: > >> This `defvar` case was devised specifically as a way to make it >> possible to provide something like fluid-let without having to >> introduce a new special form. > > Then we should document that use case. Yes, you're right. Since this case really relates more to the lexical vs dynamic binding, I think it would make more sense to add the example in a later section (with a link, of course). I still don't think I can claim with a straight face that (let (_) (defvar foo) ...) being different than (let () (defvar foo) ...) is not a bug though. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0001-Explain-more-about-defvar-foo-form-Bug-18059.patch Content-Description: patch >From 3e62f1d6d892b26993ad5553ee17a2aaeae67d8b Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 10 Feb 2018 14:06:05 -0500 Subject: [PATCH v3] Explain more about (defvar foo) form (Bug#18059) * doc/lispref/variables.texi (Defining Variables) (Using Lexical Binding): * doc/lispref/compile.texi (Compiler Errors): Emphasize that omitting VALUE for `defvar' marks the variable special only locally. --- doc/lispref/compile.texi | 5 +++-- doc/lispref/variables.texi | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/doc/lispref/compile.texi b/doc/lispref/compile.texi index 0e39866d34..70da9727ee 100644 --- a/doc/lispref/compile.texi +++ b/doc/lispref/compile.texi @@ -500,8 +500,9 @@ Compiler Errors @item Likewise, you can tell the compiler that a variable is defined using @code{defvar} with no initial value. (Note that this marks the -variable as special, i.e.@: dynamically bound.) @xref{Defining -Variables}. +variable as special, i.e.@: dynamically bound, but only for the rest +of the current binding form, or file if at top-level.) +@xref{Defining Variables}. @end itemize You can also suppress any and all compiler warnings within a certain diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index e025d3fd10..9acdb210e1 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -442,8 +442,13 @@ Defining Variables evaluated and @var{symbol} is set to the result. But if @var{symbol} is not void, @var{value} is not evaluated, and @var{symbol}'s value is left unchanged. If @var{value} is omitted, the value of @var{symbol} -is not changed in any case. Using @code{defvar} with no value is one -method of suppressing byte compilation warnings, see @ref{Compiler +is not changed in any case. + +Note that specifying a value, even @code{nil}, marks the variable as +special permanently. Whereas if @var{value} is omitted then the +variable is only marked special locally (i.e.@: for the rest of the +current binding form, or file if at the top-level). This can be +useful for suppressing byte compilation warnings, see @ref{Compiler Errors}. If @var{symbol} has a buffer-local binding in the current buffer, @@ -488,6 +493,9 @@ Defining Variables The @code{defvar} form returns @var{symbol}, but it is normally used at top level in a file where its value does not matter. + +For a more elaborate example of using @code{defvar} without a value, +@xref{Local defvar example}. @end defspec @cindex constant variables @@ -1164,6 +1172,32 @@ Using Lexical Binding (@pxref{Defining Variables}). All other variables are subject to lexical binding. +@anchor{Local defvar example} +Using @code{defvar} without a value, it is possible to bind a variable +dynamically just in one file, or in just one part of a file while +still binding it lexically elsewhere. For example: + +@example +@group +(let (_) + (defvar x) ; @r{Let-bindings of @code{x} will be dynamic within this let.} + (let ((x -99)) ; @r{This is a dynamic binding of @code{x}.} + (defun get-dynamic-x () + x))) + +(let ((x 'lexical)) ; @r{This is a lexical binding of @code{x}.} + (defun get-lexical-x () + x)) + +(let (_) + (defvar x) + (let ((x 'dynamic)) + (list (get-lexical-x) + (get-dynamic-x)))) + @result{} (lexical dynamic) +@end group +@end example + @defun special-variable-p symbol This function returns non-@code{nil} if @var{symbol} is a special variable (i.e., it has a @code{defvar}, @code{defcustom}, or -- 2.11.0 --=-=-=--