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: Always using let* Date: Mon, 15 Sep 2014 09:15:14 -0700 (PDT) Message-ID: <9dddedeb-1b55-4d6e-9fd1-5cd23b9b47b0@default> References: <87fvfukmso.fsf@Equus.decebal.nl> <93faab1c-96bd-4188-9686-3869fc027601@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1410797798 3210 80.91.229.3 (15 Sep 2014 16:16:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Sep 2014 16:16:38 +0000 (UTC) To: Cecil Westerhof , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 15 18:16:31 2014 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 1XTYx5-0004hD-5R for geh-help-gnu-emacs@m.gmane.org; Mon, 15 Sep 2014 18:16:31 +0200 Original-Received: from localhost ([::1]:32833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTYx4-0002E1-Nd for geh-help-gnu-emacs@m.gmane.org; Mon, 15 Sep 2014 12:16:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTYw5-0001Cc-Fe for help-gnu-emacs@gnu.org; Mon, 15 Sep 2014 12:15:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTYvw-0006YF-D1 for help-gnu-emacs@gnu.org; Mon, 15 Sep 2014 12:15:29 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:41477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTYvw-0006YA-6V for help-gnu-emacs@gnu.org; Mon, 15 Sep 2014 12:15:20 -0400 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s8FGFHnW016850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Sep 2014 16:15:18 GMT Original-Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8FGFGhP009517 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 15 Sep 2014 16:15:16 GMT Original-Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s8FGFF1J009499; Mon, 15 Sep 2014 16:15:15 GMT In-Reply-To: <93faab1c-96bd-4188-9686-3869fc027601@default> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8.2 (807160) [OL 12.0.6691.5000 (x86)] 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:99932 Archived-At: > > Would it be OK to always use let*? I was just bitten by the fact > > that with let you can not previous variables from the let > > statement, as is possible with setq. So I am thinking about always > > using let*, so I do not have to think about it. Or are there good > > reasons to use let when you do not need let*? >=20 > The most common reason is when you want to use a variable value > in the cadr of a binding and you do *not* want to pick up the > variable's newly bound value. IOW, precisely the opposite use > case of what you wanted when you were bit. >=20 > (setq c 3) > (let ((c (+ c 4)) (b (* c 42))) ; Use original C value: 3 ...) I should point out another reason why some people, including me, might use one or the other: To help humans read the code. When I use `let' I communicate that none of the bindings depend on earlier bindings. (The bindings are independent, which does not imply that their values are.) In particular, when a variable appears in the right side of a binding expression it is not a variable that is bound by that `let' (it may be the same symbol, but it is a different variable). In sum: If I use `let*' then look for a binding dependency. If I use `let' then don't bother to look for one. If the actual behavior of the code does not correspond to that message then the code is bugged. The point of such a convention is that a reader can more easily and quickly understand the code wrt my intention. And yes, this does mean that I end up editing the code, changing some `let's to `let*'s later, and vice versa, as it evolves. I am *not* trying to minimize my effort when writing code ("so I do not have to think about it" is misguided, IMHO). I am instead trying to minimize (human) reader effort - my code is not just about me. And yet I benefit from this more than anyone else, as I am the main reader. (And if others can more easily read it then I benefit from their better bug reports.) It's easy to write code. It's harder to understand code you have not written (just now) and to modify it without screwing things up. Yes, it's a minor consideration, but it is one that affects how I code, at least. YMMV.