🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #22

Re: Why is variable shadowing a thing in Rust?

#22
From: Tristan Wibberley
Date: Thu, 12 Nov 2026 18:32
38 lines
3081 bytes
On 22/09/2026 18:50, Stefan Ram wrote:
> Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
>> the book talks about shadowing variables, with a completely new type.
> 
>   The Rustafarians think that 
> 
> let input = input.trim();
> 
>   is clearer, because the name "input" always represents the same 
>   concept, and it becomes impossible to inadvertently use the un-
>   trimmed input later. (One also might think of every "let" in a
>   block opening a kind of "new scope".)

In fact it's the semi-colon doing that isn't it? Following the age-old
form of so many languages in which (pseudo-grammar):


  implicit-scope : statement ';' implicit-scope
                 | statement ';'


'let' just takes advantage of the new implicit-scope to cons a
dictionary overlay (or in this case an individual identifier definition)
onto a definitions dictionary stack at compile time (if you view a
compiler as an interpreter that compiles instead of executing).

-- 
Tristan Wibberley

The message body is Copyright (C) 2026 Tristan Wibberley except
citations and quotations noted. All Rights Reserved except that you may,
of course, cite it academically giving credit to me, distribute it
verbatim as part of a usenet system or its archives, and use it to
promote my greatness and general superiority without misrepresentation
of my opinions other than my opinion of my greatness and general
superiority which you _may_ misrepresent. You definitely MAY NOT train
any production AI system with it but you may train experimental AI that
will only be used for evaluation of the AI methods it implements.
Technical Details
Message-ID: <11d50o2$5r78$2@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <nnd$15514b99$3b05b221@02c0cae0f4826cd3> <lists-20260921150833@ram.dialup.fu-berlin.de> <nnd$539ee2d3$37eea303@f6e1d10301aabc89> <shadowing-20260922184407@ram.dialup.fu-berlin.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk>
Newsgroups: comp.lang.misc
Subject: Re: Why is variable shadowing a thing in Rust?
Date: Thu, 12 Nov 2026 18:32:34 +0000
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <11d50o2$5r78$2@dont-email.me>
References: <nnd$15514b99$3b05b221@02c0cae0f4826cd3>
 <lists-20260921150833@ram.dialup.fu-berlin.de>
 <nnd$539ee2d3$37eea303@f6e1d10301aabc89>
 <shadowing-20260922184407@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 12 Nov 2026 18:32:35 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="191720"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19OrbkjE9hAsiTd+eZZfRRAlJT7RcbWFWeE87jvbcjhEg=="; posting-host="61bea730185dc00b7c39d5f27bd5f472"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Vb5TjUVFSd41oXIpjyFn4ZVgZ+0= sha256:bvxBmu4E1uNOCDIbAbvnlPIr3zRjJ4xzWrfAQajDmIo=
	sha1:qd5MMqyqxqbnMjP2PnMm0ZfrRLE= sha256:eiJ0KKjbTqWEAh7FHe+bXC130zCJPzCf/QpBqd0dHFU=
In-Reply-To: <shadowing-20260922184407@ram.dialup.fu-berlin.de>
Content-Language: en-GB