From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Understanding the "let" construct and the setting of variables Date: Fri, 18 Dec 2020 18:48:28 +0100 Message-ID: <20201218174828.GA8685@tuxteam.de> References: <87eejnyr37.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="6TrnltStXW4iwmi0" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32377"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 18 18:49:33 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kqJsi-0008Jf-Sp for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 18 Dec 2020 18:49:32 +0100 Original-Received: from localhost ([::1]:46622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqJsh-0005lz-U0 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 18 Dec 2020 12:49:31 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqJrm-0005ln-LV for help-gnu-emacs@gnu.org; Fri, 18 Dec 2020 12:48:35 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]:39238) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1kqJrk-0004x9-EV for help-gnu-emacs@gnu.org; Fri, 18 Dec 2020 12:48:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:Date; bh=z1DZpEv8Yq/AwHx7uB0UDG2/BzlS82edA14aZhvQxHs=; b=myLfzjISRGr2ZJTUTK2sbposO585lfLK60W93+wTOpNMk+z+80asq+piVyV7WY+13wAk864g1DB666K6VvPDwm1cRjH2wjzCGji09VqSCdin7X5F8uTAhVbsIEzMfo4ECEC1baN4NbxrAau2X4k4QlTyE7exlBbmTlHLiaockaFA9th9sR4FlLmRtrZM5KNKfpP/uLBF2bCaA7EysoBFuwBiiNwdPHi3p1phjo1Ig7gy+FI6tGxJ9OtFzW6Kqk6+M+0G67Wm3twSFhnbeN8HLrOvHhR6kRG8HQFmKDOyavK0GioEf3JhiiXjv3Mwu5fyrlv/6qRGmqBxT4+R8FsyAQ==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1kqJrg-0004Fc-JA for help-gnu-emacs@gnu.org; Fri, 18 Dec 2020 18:48:28 +0100 Content-Disposition: inline In-Reply-To: <87eejnyr37.fsf@zoho.eu> Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126514 Archived-At: --6TrnltStXW4iwmi0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 18, 2020 at 06:14:04PM +0100, Emanuel Berg via Users list for t= he GNU Emacs text editor wrote: > steve-humphreys wrote: >=20 > > Let's introspect two questions. > > > > 1. In what simple circumstances would one use a "setq" in > > the body of a let? >=20 > When one wants to change a global variable that already exists > outside of the function. Or a local, if that has been locally bound, e.g. by a let or a function param: (defun collatz-sequence (n) ; [1] (while (> n 1) (insert (format "%5d\n" n)) (setq n (if (=3D (mod n 2) 0) (/ n 2) (+ (* n 3) 1))))) (collatz-sequence 11) =3D> 11 34 17 52 26 13 40 20 10 5 16 8 4 2 Yeah, the 1 at the end is missing. Left as an exercise for the reader :) The setq in the function's last line modifies the n which is local to the function, because it's in the parameter list (which is roughly equivalent to a let list). Cheers [1] https://en.wikipedia.org/wiki/Collatz_conjecture - t --6TrnltStXW4iwmi0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAl/c62wACgkQBcgs9XrR2kbe3wCdGBx7bJXX6HUa9d9zhFn5XBHT mfsAn3BjatNI2ErcaNcZxHnIj5t9fso8 =5YSS -----END PGP SIGNATURE----- --6TrnltStXW4iwmi0--