Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If an experiment works, something has gone wrong.


devel / comp.lang.python / Re: Behavior of the for-else construct

SubjectAuthor
* Re: Behavior of the for-else constructChris Angelico
`- Re: Behavior of the for-else constructGreg Ewing

1
Re: Behavior of the for-else construct

<mailman.141.1646355333.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17318&group=comp.lang.python#17318

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 11:55:20 +1100
Lines: 115
Message-ID: <mailman.141.1646355333.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<621325684.471007.1646354302946@mail.yahoo.com>
<CAPTjJmpNT4TTRiYRD2G73EsDp3O+_Tg_sF2vp3Tf0vC-EJWqAA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de rNa3zHRmVA6RkGuKzj/u9Qm4SIDPYg/Da5HC+CK5kY2A==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=i6ReYfFz;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'comments': 0.03; '(which':
0.04; '2022': 0.05; 'bunch': 0.05; 'loop': 0.07; 'mar': 0.07;
'spaces': 0.07; 'string': 0.07; 'else:': 0.09; 'fact,': 0.09;
'identical': 0.09; 'language,': 0.09; 'speak.': 0.09; 'string,':
0.09; 'theory': 0.09; 'treated': 0.09; 'typically': 0.09; 'way?':
0.09; 'problem.': 0.15; 'syntax': 0.15; 'alphabets': 0.16; 'are.':
0.16; 'arguments': 0.16; 'avi': 0.16; 'chrisa': 0.16;
'considered,': 0.16; 'constantly': 0.16; 'construct.': 0.16;
'directory,': 0.16; 'earlier,': 0.16; 'extensions': 0.16;
'filenames': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'gross': 0.16; 'important:': 0.16; 'languages.':
0.16; 'nested': 0.16; 'odd': 0.16; 'okay.': 0.16; 'ones.': 0.16;
'popular.': 0.16; 'recall': 0.16; 'solves': 0.16; 'subject:else':
0.16; 'subset': 0.16; 'tends': 0.16; 'these.': 0.16; 'tries':
0.16; 'vector': 0.16; 'victim': 0.16; 'wrote:': 0.16; 'python':
0.16; 'code.': 0.17; 'uses': 0.19; 'to:addr:python-list': 0.20;
'language': 0.21; "i've": 0.22; 'languages': 0.22; 'fri,': 0.22;
'maybe': 0.22; 'code': 0.23; 'command': 0.23; "i'd": 0.24;
'to:name:python-list@python.org': 0.24; '(and': 0.25;
'programming': 0.25; 'seems': 0.26; 'behavior': 0.26; 'suspect':
0.26; 'else': 0.27; 'bit': 0.27; 'thinking': 0.28; 'takes': 0.31;
'putting': 0.31; 'wide': 0.31; 'think': 0.32; 'everyone': 0.32;
'question': 0.32; 'expand': 0.32; 'language.': 0.32; 'logical':
0.32; 'python-list': 0.32; 'topic,': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'mark': 0.32; 'but': 0.32; "i'm": 0.33;
'subject:for': 0.33; 'windows': 0.34; 'able': 0.34; 'mean': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34; 'fine':
0.35; 'words': 0.35; 'yes,': 0.35; 'from:addr:gmail.com': 0.35;
'recipient': 0.36; 'files': 0.36; 'built': 0.36; 'people': 0.36;
'those': 0.36; 'special': 0.37; 'key': 0.64; 'extend': 0.64;
'your': 0.64; 'similar': 0.65; 'look': 0.65; 'time.': 0.66;
'earlier': 0.67; 'now,': 0.67; 'types': 0.67; 'back': 0.67;
'entire': 0.67; 'deeply': 0.69; 'perfectly': 0.69; 'sequence':
0.69; 'front': 0.70; 'rules': 0.70; 'longer': 0.71; 'free': 0.72;
'deal': 0.73; "you'll": 0.73; 'tools': 0.74; 'hundreds': 0.75;
'name,': 0.75; 'combination': 0.76; 'treat': 0.76; 'reply': 0.77;
'major': 0.78; 'leads': 0.81; 'names,': 0.81; 'left': 0.83;
'variety': 0.84; '(like': 0.84; '(other': 0.84; 'balanced': 0.84;
'characters': 0.84; 'comments,': 0.84; 'exactly.': 0.84;
'further,': 0.84; 'lay': 0.84; 'quotes': 0.84; 'strings': 0.84;
'weird': 0.84; 'differently': 0.91; 'fat': 0.91; 'viewed': 0.93;
'keywords': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=vGM5ihROGqsmKrH0XZyPKOR705h0zj0zzNQTLAVv9YY=;
b=i6ReYfFzwivUw6IcEJzA0xxMnWRaRRzp6xnaR4/rSoLoY3//FynlHjpjmna1PdZ+KQ
Yc/Zxqo30BtItblJATahdMPtMC+ksbfZ67RU3SsS1hbVq/yL/0c+apwUgy06Y3EV34mf
ZhHVFRFWXB296pE1lQMNgxr5V9tL+ciJCH13u0+8RGQr1UAHPI8fCPr6z9RUUnhuywIT
IbKXerZjeBbyaHY73DQlqkF+4vEOHP9/0say3JXfJ4jahwk0RKIQHFEYOJkOmtKswd+O
tA/RgL8e/vWaFfoxoP+lRWJaHSqocwWaMQct2lSwvqMXqcLgLaPlhuKCISm/b0oUE3E2
fn1Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=vGM5ihROGqsmKrH0XZyPKOR705h0zj0zzNQTLAVv9YY=;
b=4XXL41VqDj5CBBa00N687QJHWN/l/r8rpnHIO6HkKPnElIhJzxd5LOpY0GSgHI89z2
m4cxxg7HDo3deBxkuLxZiCIrNbLtkwBKPGlJIxX/LPV8hUyXl3KSBe+zfeIEacv2iB6L
+D/rBrrbRbAMO5ccBoxJXx3aG9YoSHcUE+NS0zgfCvmNNo7U4on0v+VXo62QDwdseASZ
Q0aRJ0XOjkPkKqVMSV+heC+tOcihd58HzsgubEd5YZyOrPVLB4frMZz+zlatvsKlxxMg
HnCsc8Ml9DmJCzdDEeUpz2TsfUdVFcXKZ8sio3GuqADl5lmRGOJit5mratYcop6GMd+g
sdCQ==
X-Gm-Message-State: AOAM531pQGNH5ZP/asnwE70iXbcgt0OtwDvYaazJ3iaZRpHarxzj31Ig
EVxuLMIqSFoG+iPUTVPwXspxCfcluLKW70onKw5kmRUu
X-Google-Smtp-Source: ABdhPJyTpa5BfdvUhml809PSYfiKu6Bo+n0ibAy+mzee2vx0dopHBG2BRcwHL9bPXvtRaia9oPMhu4Sn2w1dgQHjSi4=
X-Received: by 2002:adf:f801:0:b0:1f0:7675:f5e6 with SMTP id
s1-20020adff801000000b001f07675f5e6mr456856wrp.564.1646355331428; Thu, 03 Mar
2022 16:55:31 -0800 (PST)
In-Reply-To: <621325684.471007.1646354302946@mail.yahoo.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmpNT4TTRiYRD2G73EsDp3O+_Tg_sF2vp3Tf0vC-EJWqAA@mail.gmail.com>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<621325684.471007.1646354302946@mail.yahoo.com>
 by: Chris Angelico - Fri, 4 Mar 2022 00:55 UTC

On Fri, 4 Mar 2022 at 11:39, Avi Gross via Python-list
<python-list@python.org> wrote:
>
> Rob,
>
> I regularly code with lots of comments like the one you describe, or mark the end of a region that started on an earlier screen such as a deeply nested construct.
>
> I have had problems though when I have shared such code and the recipient strips my comments and then later wants me to make changes or even just explain it! My reply tends to be unprintable as in, well, never mind!
>

If they strip out the comments, you can be confident that the comments
were unhelpful :)

> This leads to a question I constantly ask. If you were free to design a brand new language now, what would you do different that existing languages have had to deal with the hard way?
>

Very good way to start thinking. In fact, I'd recommend going further,
and actually designing the entire language. (Don't bother actually
writing an implementation, but fully lay out the syntax and
semantics.) It's a great exercise, and you'll learn why things are the
way they are.

> I recall when filenames and extensions had a limited number of characters allowed and embedded spaces were verboten. This regularity made lots of code possible but then some bright people insisted on allowing spaces and you can no longer easily do things like expand *.c into a long line of text and then unambiguously work on one file name at a time. You can often now create a name like "was file1.c and now is file2.c" and it seems acceptable. Yes, you can work around things and get a vector or list of strings and not a command line of text and all things considered, people can get as much or more work done.
>

I don't remember when embedded spaces were verboten, so I'm guessing
you're talking about 1970s or earlier, on mainframes? In MS-DOS, it
was perfectly possible to have spaces in file names, and OS/2 also had
that flexibility (and used it for special files like "EA DATA. SF" on
a FAT disk). Windows forbade a bunch of characters in file names, but
other systems have always been fine with them.

It's not only file names that can be multiple words in a single
logical argument. The Windows "start" command has a bizarreness where
it takes a quoted string as a title, but a second quoted string as a
file name, so <<start c:\some_dir>> will open that directory, <<start
"c:\some_dir">> opens a shell with a title of "c:\some_dir", and
<<start "" "c:\some_dir">> opens the directory, even if it has spaces
in it. It's much better to treat arguments as a vector of strings
rather than a single string, as the start command tries to.

> I have seen major struggles to get other character sets into languages. Any new language typically should have this built in from scratch and should consider adding non-ASCII characters into the mix. Mathematicians often use lots of weird braces/brackets as an example while normal programs are limited to [{( and maybe < and their counterparts. This leads to odd Python behavior (other languages too) where symbols are re-used ad nauseam. { can mean set or dictionary or simply some other way to group code.
>

Tell me, which is more important: the way the code looks, or the way
it is typed? Because your *editor* can control both of these.

> So I would love to see some key that allows you to do something like L* to mean the combination is a left bracket and should be treated as the beginning of a sequence expected to end in R* or perhaps *R. That would allow many other symbols to be viewed as balanced entities. Think of how Python expanded using single and double quotes (which arguably might work better if balanced this way) to sometimes using triple quotes to putting letters like "b" or "f" in front to make it a special kind of string.
>

Okay. Design that in an editor and see if it catches on.

I've seen a wide variety of bracket-matching tools (like color-coding
all types of bracket according to what they pair with), but none of
them really get popular. Baking it into the language means that
everyone who uses the language has to be able to work with this.

Flesh out this "L*" idea, and explain how it solves the problem. What
does it do to the asterisk?

> But I suspect programming might just get harder for those who would not appreciate a language that used (many) hundreds of symbols. I do work in many alphabets and many of them pronounce and use letters that look familiar in very different ways and sound them differently and invent new ones. Every time I learn another human language, I have to both incorporate the new symbols and rules and also segregate them a bit from identical or similar things in the languages I already speak. It can be quite a chore. But still, I suspect many people are already familiar with symbols such as from set Theory such as subset and superset that could be used as another pair of parentheses of some type Having a way to enter them using keyboards is a challenge.
>

Exactly.

> Back to the topic, I was thinking wickedly of a way to extend the FOR loop with existing keywords while sounding a tad ominous is not with an ELSE but a FOR ... OR ELSE ...
>

for victim in debtors:
if victim.pay(up): continue
if victim.late(): break
or else:
victim.sleep_with(fishes)

There's something in this.

ChrisA

Re: Behavior of the for-else construct

<j8d998Fs69dU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17324&group=comp.lang.python#17324

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 14:45:12 +1300
Lines: 12
Message-ID: <j8d998Fs69dU1@mid.individual.net>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<621325684.471007.1646354302946@mail.yahoo.com>
<CAPTjJmpNT4TTRiYRD2G73EsDp3O+_Tg_sF2vp3Tf0vC-EJWqAA@mail.gmail.com>
<mailman.141.1646355333.2329.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 83jBHRxjGwidHz+3VIxhmAFM+ob4Tmy5Xlta0i8NPv4NDv6qnp
Cancel-Lock: sha1:xU/Deegx7iRGtqWT12rHr3u3SU4=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.141.1646355333.2329.python-list@python.org>
 by: Greg Ewing - Fri, 4 Mar 2022 01:45 UTC

On 4/03/22 1:55 pm, Chris Angelico wrote:
> It's much better to treat arguments as a vector of strings
> rather than a single string, as the start command tries to.

It would be nice if you could, but as I understand it, Windows always
passes arguments to a program as a single string, and then it's up to
the program to split it up how it wants. Different programs do that in
different ways, hence the inconsistencies in how quoting and whitespace
is handled.

--
Greg

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor