From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: sending function arguments to recursive function calls Date: Fri, 17 May 2013 07:31:24 -0700 Message-ID: <2AC6E6871319483CABA0387DEF8B39CC@us.oracle.com> References: <0F54256BD7B94384AC4DDA919D502C20@us.oracle.com><4D1DF48A7223443FA454C07B20B80E21@us.oracle.com> <87mwrt7py6.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1368801117 4129 80.91.229.3 (17 May 2013 14:31:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 May 2013 14:31:57 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, 'Stefan Monnier' To: "'Dmitry Gutov'" , "=?iso-8859-1?Q?'Gauthier_=D6stervall'?=" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 17 16:31:58 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 1UdLhN-0002T6-JZ for geh-help-gnu-emacs@m.gmane.org; Fri, 17 May 2013 16:31:57 +0200 Original-Received: from localhost ([::1]:53839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdLhN-0006Ha-2r for geh-help-gnu-emacs@m.gmane.org; Fri, 17 May 2013 10:31:57 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdLh8-0006HF-0E for help-gnu-emacs@gnu.org; Fri, 17 May 2013 10:31:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdLh3-00048Q-0M for help-gnu-emacs@gnu.org; Fri, 17 May 2013 10:31:41 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:32368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdLh2-00048J-QQ for help-gnu-emacs@gnu.org; Fri, 17 May 2013 10:31:36 -0400 Original-Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r4HEVVNa012505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 17 May 2013 14:31:33 GMT Original-Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4HEVUMh009858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 17 May 2013 14:31:31 GMT Original-Received: from abhmt120.oracle.com (abhmt120.oracle.com [141.146.116.72]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r4HEVUAp015244; Fri, 17 May 2013 14:31:30 GMT Original-Received: from dradamslap1 (/10.159.149.30) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 17 May 2013 07:31:29 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: Ac5S+cGt3yKaLNB1SF+f1a0enGP5DwABglMg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 In-Reply-To: <87mwrt7py6.fsf@yandex.ru> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 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:90873 Archived-At: > 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 There is nothing ugly about that behavior. 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 Which is also not ugly and not unusual. There is no binding of `bar' lexically visible in `baz'. Dynamic and lexical binding are very different. That's all. Each has its advantages. Lexical binding is generally cleaner (correct for funargs etc.), so it is simpler to understand (WYSIWYG, where the `S' is all about lexical scope). As such, it can often allow compilation to more efficient code. And it can facilitate program proving and transformation, but mainly for "pure" (referentially transparent) languages, not full Lisp. 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. -- Some other background/discussion: http://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding http://en.wikipedia.org/wiki/Static_scoping#Dynamic_scoping http://stackoverflow.com/questions/321000/what-are-the-advantages-of-dynamic-sco ping http://stackoverflow.com/questions/2979428/uses-for-dynamic-scope http://c2.com/cgi/wiki?DynamicScoping http://academic.udayton.edu/saverioperugini/courses/cps343/lecture_notes/scope.h tml http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node43.html http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html http://devblog.avdi.org/2008/02/23/why-monkeypatching-is-destroying-ruby/