From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.help Subject: Re: sending function arguments to recursive function calls Date: Sun, 19 May 2013 20:57:44 +0400 Message-ID: <51990488.7000306@yandex.ru> References: <0F54256BD7B94384AC4DDA919D502C20@us.oracle.com><4D1DF48A7223443FA454C07B20B80E21@us.oracle.com> <87mwrt7py6.fsf@yandex.ru> <2AC6E6871319483CABA0387DEF8B39CC@us.oracle.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1368982687 7354 80.91.229.3 (19 May 2013 16:58:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 19 May 2013 16:58:07 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 19 18:58:07 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 1Ue6vu-0005ze-UJ for geh-help-gnu-emacs@m.gmane.org; Sun, 19 May 2013 18:58:07 +0200 Original-Received: from localhost ([::1]:53441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ue6vu-0003TJ-Jn for geh-help-gnu-emacs@m.gmane.org; Sun, 19 May 2013 12:58:06 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ue6vb-0003Sw-TZ for help-gnu-emacs@gnu.org; Sun, 19 May 2013 12:57:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ue6vT-0002iV-91 for help-gnu-emacs@gnu.org; Sun, 19 May 2013 12:57:47 -0400 Original-Received: from mail-la0-x22e.google.com ([2a00:1450:4010:c03::22e]:63254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ue6vT-0002iN-1U for help-gnu-emacs@gnu.org; Sun, 19 May 2013 12:57:39 -0400 Original-Received: by mail-la0-f46.google.com with SMTP id er20so1525861lab.19 for ; Sun, 19 May 2013 09:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding:x-antivirus:x-antivirus-status; bh=qkMp/ckQ8iiTAJuQlAuY2cOLrY/qwoFzlpq/VmFBQXA=; b=BnaerY9XD02Mr8ky+7L3cwD3mx0iri4EscgfF3fj3rTpMZIBSUT/1Gs10JkQgRIq4m /gKcUqFqyDb0HMAtVno3ctJYPeGfobrUuo9MM0eAGEul+1/ZTeDjtdhDwzb7yMz+nTX9 eTE57tm2lIp7QFSdB7FqjCK5PpycTM82qONj2uCNR72wEoymGbUGP0RGUEIvzYK+SrcE JzT7SQI+RgRgFULpSfn5yWdxH5/ToCoHqH0OR5BN1LfUe3i5K9FD+Mayk36b38PbVWSz Djg9iNooIHsHXJK+rQP/m5wFBASDrISZOVKjPaFEbGDLyzt+zB6+QIcHwNE1oDPJuZnG 3zGQ== X-Received: by 10.112.167.229 with SMTP id zr5mr433067lbb.7.1368982657959; Sun, 19 May 2013 09:57:37 -0700 (PDT) Original-Received: from [127.0.0.1] ([178.252.98.87]) by mx.google.com with ESMTPSA id jr19sm8521527lab.0.2013.05.19.09.57.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 19 May 2013 09:57:36 -0700 (PDT) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: <2AC6E6871319483CABA0387DEF8B39CC@us.oracle.com> X-Antivirus: avast! (VPS 130519-0, 19.05.2013), Outbound message X-Antivirus-Status: Clean X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22e 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:90920 Archived-At: On 17.05.2013 18:31, Drew Adams wrote: >> This is the ugly side of dynamic scoping. >> (defun foo () (let ((bar 42)) (baz))) >> (defun baz () bar) >> (foo) ; => 42 >> baz ; => void-variable error > > Huh? I guess you meant to write > (baz) ; => "void-variable bar" error No, I meant exactly to write variable reference, not function call, to illustrate that it's not defined globally. > There is nothing ugly about that behavior. It's ugly because this kind of code is hard to reason about and, consequently, hard to modify. Suppose I want to rewrite `foo' (and suppose it's longer than this one line). Can I rename `bar' to something else? No idea: to be absolutely sure, I have to search the definitions of all functions that `foo' calls, and if I find a `bar' reference in any of them, I'll now have to search for any other functions that call them, etc. IOW, this makes for terrible composability. The behavior is ugly because it allows the code to be written this way. A worse example is when `bar' is one of the arguments to `foo' (ugh). > The `let' binds variable `bar' for the dynamic extent of the call to `foo'. > There is no other binding of `bar' or assignment to it here, so `(baz)' refers > to an unbound variable `bar'. > > What happens with lexical scoping? > (foo) ; => "void-variable bar" error > (baz) ; => "void-variable bar" error As it should. Contrast this with the situation when `bar' has been `defvar'ed in advance. Both functions would know that this var is global, so if it's renamed in some place, it definitely should be renamed in all functions that reference it. This is what I can call the light side of dynamic scoping, and it's how the term "dynamic binding" is often defined. > Dynamic binding facilitates user extension ("monkey patching"). And yes, this > is particularly important for a dynamic user environment like Emacs. > > It is easy to find references lauding the benefits of lexical binding (most > languages use only lexical binding). Stallman explains well why dynamic binding > is important for Emacs: > http://www.gnu.org/software/emacs/emacs-paper.html#SEC17. I could offer some criticism for the paper, but there's really no need. Just recall that Emacs is on track to eventually replace dynamic scoping with lexical scoping everywhere, with exceptions for defvar'ed vars (controlled dynamic binding), and nobody is really arguing that Emacs will become too hard to customize as a result. Nobody reasonably well-informed, anyway.