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: Tue, 7 May 2013 07:04:15 -0700 Message-ID: <4D1DF48A7223443FA454C07B20B80E21@us.oracle.com> References: <0F54256BD7B94384AC4DDA919D502C20@us.oracle.com> 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 1367935480 19733 80.91.229.3 (7 May 2013 14:04:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 May 2013 14:04:40 +0000 (UTC) To: "=?iso-8859-1?Q?'Gauthier_=D6stervall'?=" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 07 16:04:38 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 1UZiVS-0005hp-9F for geh-help-gnu-emacs@m.gmane.org; Tue, 07 May 2013 16:04:38 +0200 Original-Received: from localhost ([::1]:51943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiVR-0000mu-Oo for geh-help-gnu-emacs@m.gmane.org; Tue, 07 May 2013 10:04:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiVG-0000mi-3v for help-gnu-emacs@gnu.org; Tue, 07 May 2013 10:04:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZiVE-0001Cq-MA for help-gnu-emacs@gnu.org; Tue, 07 May 2013 10:04:26 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:42005) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiVE-0001CX-Eg for help-gnu-emacs@gnu.org; Tue, 07 May 2013 10:04:24 -0400 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r47E4KPv014005 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 7 May 2013 14:04:21 GMT Original-Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r47E4K5T015567 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 7 May 2013 14:04:21 GMT Original-Received: from abhmt105.oracle.com (abhmt105.oracle.com [141.146.116.57]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r47E4KPp020396; Tue, 7 May 2013 14:04:20 GMT Original-Received: from dradamslap1 (/10.159.172.69) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 07 May 2013 07:04:20 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: Ac5LFaODlPivbNBPSRa+V4HjceJELQAEtbdA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 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:90535 Archived-At: > > The key to the puzzle is this little declaration in the > > first comment of the file: > > > > ;;; face-remap.el --- Functions for ... -*- lexical-binding: t -*- > > > > That `lexical-binding t' tells Emacs that the code in this > > file is meant to be understood with the variable > `lexical-binding' bound to t (locally). > > Thanks for the kind words and the explanation. I do not feel very > confident about having a function that relies on a file scope setting > of lexical-binding, which as in this case happens 300 lines earlier. > Wouldn't it be better to have functions that work whatever the value > of lexical-binding, if possible? I agree. Sometimes, however, you specifically want the function definition to take advantage of one kind of scoping/binding or the other. IOW, when it makes no difference, then yes, it would be nice not to be bothered with the difference. ;-) When it does make a difference, that is, when you want it to make a difference, then it should be easy to choose and it should be clear what is going on. Emacs Lisp does not particularly make things clear, IMO. Common Lisp does a pretty good job of helping lexical and dynamic binding cohabit. Emacs Lisp does not do such a great job, IMO. As Stefan pointed out: Reality is that there are 2 Emacs Lisps. One is the dynamically scoped Elisp, and the other is the lexically scoped Elisp. They are very similar, but they are two different languages. > > An alternative to using a lexical binding here would be to > > simply use this: > > `(lambda () (interactive) (text-scale-adjust (abs ',inc))) > > If this alternative works whatever lexical-binding, it seems superior > to me. Isn't it? Yes. That's my opinion, anyway. In this case (and in many others), there is no _logical_ reason to pass a variable and have that variable be looked up lexically when the lambda is invoked. All that is needed is the variable's value at the time the lambda is _constructed_. Anything else is overkill. But logic is not the only thing involved here. Disadvantages of substituting the value can include: (a) backquote syntax, or its equivalent, is less readable and (b) the byte compiler might not be able to compile the lambda in a performant way. I'm no expert on Emacs byte compilation, but it's possible that the byte compiler just punts on a dynamically constructed sexp such as the one above, even though it might be able to figure out that the result in this case is straightforward. Dunno. Lexical binding was added to Emacs relatively recently. With time, perhaps it and dynamic binding will become better roommates. And certainly, with time, users will become more used to lexical binding and to looking out for lexical/dynamic binding gotchas. For one thing, you will no doubt be reflexively looking for a local-variable binding declaration in the file, right? ;-) And you will be looking for free variables, and when you notice one you will ask yourself whether it will be evaluated using lexical or dynamic binding. IOW, you will internalize things like this help thread.