Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Linux is obsolete -- Andrew Tanenbaum


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

SubjectAuthor
o Re: Behavior of the for-else constructAvi Gross

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigr...@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Sat, 5 Mar 2022 17:48:40 +0000 (UTC)
Lines: 48
Message-ID: <mailman.193.1646502528.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiK5sBXLrgwFFA+N@cskk.homeip.net>
<fa40d3c4-ea8b-ac1f-d7e4-a23eea3de7fb@btinternet.com>
<1659671269.122157.1646502520833@mail.yahoo.com>
Reply-To: Avi Gross <avigross@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de q9eIZDaLNKcTGhp1Cz30QAeFxn1zhEAxxmQOGQ2mftHg==
Return-Path: <avigross@verizon.net>
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=verizon.net header.i=@verizon.net header.b=QuEvb4VC;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.016
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '(for': 0.05; '2022': 0.05;
'loop': 0.07; 'mar': 0.07; 'matches': 0.07; 'matching': 0.07;
'task.': 0.07; 'always,': 0.09; 'construct': 0.09; 'it)': 0.09;
'meant': 0.09; 'theory': 0.09; 'values.': 0.09; 'url:mailman':
0.15; 'arguments': 0.16; 'branches,': 0.16; 'branching': 0.16;
'cameron': 0.16; 'coincidence.': 0.16; 'crashed': 0.16;
'formidable': 0.16; 'integer': 0.16; 'iteration': 0.16; 'looping':
0.16; 'many,': 0.16; 'matched': 0.16; 'objects.': 0.16;
'patterns': 0.16; 'simpson': 0.16; 'something.': 0.16;
'subject:else': 0.16; 'unpacking': 0.16; 'wrote:': 0.16; 'python':
0.16; 'calls': 0.19; 'to:addr:python-list': 0.20; 'language':
0.21; 'languages': 0.22; 'ran': 0.22; 'sat,': 0.22; 'code': 0.23;
'idea': 0.24; 'to:name:python-list@python.org': 0.24; '(and':
0.25; 'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'behavior': 0.26; 'object': 0.26; 'pattern':
0.26; 'bit': 0.27; 'function': 0.27; 'done': 0.28; 'group.': 0.28;
'series': 0.28; 'suggest': 0.28; 'seem': 0.31; 'takes': 0.31;
'wide': 0.31; 'url-ip:188/8': 0.31; 'think': 0.32; 'concept':
0.32; 'conversation': 0.32; 'needed,': 0.32; 'objects': 0.32;
'python-list': 0.32; 'returning': 0.32; 'zero': 0.32; 'unless':
0.32; 'but': 0.32; 'subject:for': 0.33; 'there': 0.33; 'someone':
0.34; 'mean': 0.34; 'header:In-Reply-To:1': 0.34; 'complex': 0.35;
'item': 0.35; 'built': 0.36; 'errors': 0.36; 'possibly': 0.36;
'currently': 0.37; 'really': 0.37; 'using': 0.37; 'class': 0.37;
'way': 0.38; 'could': 0.38; 'added': 0.39; 'enough': 0.39;
'setting': 0.39; 'use': 0.39; 'break': 0.39; 'still': 0.40;
'exact': 0.40; 'gone': 0.40; 'match': 0.40; 'serious': 0.40;
'both': 0.40; 'want': 0.40; 'potential': 0.60; 'including': 0.60;
'provide': 0.60; 'above': 0.62; 'from:': 0.62; 'to:': 0.62;
'seen': 0.62; 'come': 0.62; 're:': 0.64; 'your': 0.64; 'among':
0.65; 'wish': 0.66; 'shows': 0.67; 'types': 0.67; 'further': 0.69;
'order': 0.69; 'await': 0.69; 'counter': 0.69; 'repeatedly': 0.69;
'below': 0.69; 'content.': 0.70; 'older': 0.70; 'free': 0.72;
'features': 0.75; 'potentially': 0.76; 'out,': 0.78; 'sent:':
0.78; 'header:Reply-To:1': 0.79; 'returned': 0.81; 'var': 0.81;
'left': 0.83; 'capture': 0.84; 'disagree': 0.84; 'match.': 0.84;
'resembled': 0.84; 'rob': 0.84; 'sake,': 0.84; 'statement.': 0.84;
'broke': 0.91; 'door': 0.91; 'variation': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1646502525; bh=zinBoNpPdu33Z0tyfAOAu89K7Yv6gU+i08zbSBLJioM=;
h=Date:From:Reply-To:To:In-Reply-To:References:Subject:From:Subject:Reply-To;
b=QuEvb4VCRMlG+i0tt8b2GyxGBjyMP3J8Q3KPZbi+APErgnSFf557hWguqGQ+GPMX3DQGbUnn67MtpwVm8RGYuqLcSRRHgyUoARIE//eIBWBVutTk08rHwfoTlz+vsWFVBAc6juOUVc5SuRvwpeVo89f9eY8Ybv8HAOu8KoVVdngau0VXWKoSomwaGZo6UMeZnKjfMmM2Dgy3HalDr3QCrqtUWrebj1XxU/ynWNnWLzrINclzwR5MU1TdigUkLyJf8NVgAEbQfiwTgnv9wKF0dPjQyKs0QdsUOaj7+qajRR2BSmm5yrRzmSDsyODHFYEy/bfpFReSAW1C6m7tuHrG1Q==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1646502525; bh=e7RXtvJ1MA1+pwmRUHYDwsFJlkGiwpK4fNwm/TmY7v5=;
h=X-Sonic-MF:Date:From:To:Subject:From:Subject;
b=huPHCCdGkJ+5rZBxJUYt6kD7GCf8vyQCsVubF/H/1+2EInwqYMhiqCsjKPT2Kt4ulCHUrG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9sf9BHW_3RoSsRdzVD4WnfX74HT_QEay_KRwe
nNTKY4EmFpUAwiJD8try3vHK35mR5c6mBNfSgd9RlPARSyH6_lIhrXLBjpQliejNiVOkwGYOqLBS
XY8SSJPhz1MzRIBuUiRrSAHMHtGouTi5qxYmYPN58h.p9LtoSJN7wwLbZwP8NDFzdj_D8hDmtiN8
1KlTs.zRBN7fTBgruKAIpjRjvbSaX4ATw.qw4_mgYo3gWJVje6bg45eQUBtuSpGCdjFYVAIadKkz
QGI2HgbZ6rN7zQ3__UUH6q1iGOlj74O3uTb.BmrrpHwRS597U4f5pRawTqJ6Hul4xa6mRSZy5r5u
JELWWZVfvMp_5vOC2xfRpORuFqaVE85_xuXGizpMntHlLkWjGg2a_y_zms7G1QHo8gc5wozzFOEN
dSlO0K5uOEGrmpHn9aGcvTEL00lMJnow-
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <fa40d3c4-ea8b-ac1f-d7e4-a23eea3de7fb@btinternet.com>
X-Mailer: WebService/1.1.19797 aolwebmail
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: <1659671269.122157.1646502520833@mail.yahoo.com>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiK5sBXLrgwFFA+N@cskk.homeip.net>
<fa40d3c4-ea8b-ac1f-d7e4-a23eea3de7fb@btinternet.com>
 by: Avi Gross - Sat, 5 Mar 2022 17:48 UTC

Since we still seem to be dreaming, I wonder when someone will suggest using some variation of the new match statement. All you need is for the for loop (and possibly other such constructs) to return some kind of status that can be matched

match (for var in something:
... ) :
case break():
case skipped():
case did(1):
case didall():

case crash():
case _ :

As always, the above is not even pseudocode. But my point is there are languages I have seen that are built on such pattern matching and provide abilities to do a multi-way branching as long as you are very careful about the order you place the things to match.

If not understood, the above function calls are meant to suggest something. For argument's sake, the for loop could return a non-negative number that shows the number of iterations done completely or even partially. It could also return various out-of-band (perhaps negative) values. So if it is skipped you get a zero or a value matching what my make-believe function skipped() returns. If the loop just ran once, it matched did(1). If it completed without breaks, it didall() and if it broke out, or crashed it matches something. I hope the idea comes across, even if you disagree with my indenting or exact method.

Constructs like the above do in theory allow some really complex matching and often in a way easier to understand than having endless clauses added below the for group.

But as repeatedly stated, Python currently has no concept of returning a value directly from a for loop or lots of other things. A brand new language that superficially resembled python could be designed but that is a rather formidable task.

And where does it end? I mean you could set it up so the language allows you to return an invisible (meaning it does not print unless you ask for it) object among many possible objects.

The simplest object may be an integer or perhaps an object of a class with a name like counter so you matched against counter(1) or against counter(n) if you want to capture the exact number for further processing. Various other object types might be returned including one that tells you about a break and also on which iteration it broke out of or even the value of the item it was looping on at the moment. If this starts looking a bit like how errors can be created and propagated, that is no coincidence.

But the above also might come with serious overhead. And for many, it would not be seen as necessary. I will say that by allowing the match statement in the current form, the door has been opened wide for all kinds of potential enhancements. Older code and features may be left alone, but newer code is now free to do esoteric things. If I rewrote my call to the loop into a function that takes arguments including the data I want to have used and internally does the for loop while setting various variables that capture all kinds of info needed, then it potentially could return one of a series of objects you could pattern match against to your heart's content. A call to the function could be used in a match statement vaguely as in my hand-waving above. And of course you can use unpacking to make all kinds of compound patterns if done carefully.

I think my part of this endless conversation may have gone a bit beyond far enough and I await some new topics.

-----Original Message-----
From: Rob Cliffe via Python-list <python-list@python.org>
To: python-list@python.org
Sent: Sat, Mar 5, 2022 7:15 am
Subject: Re: Behavior of the for-else construct

On 05/03/2022 01:15, Cameron Simpson wrote:
>
> I sort of wish it had both "used break" and "did not use break"
> branches, a bit like try/except/else.
And "zero iterations".
Rob Cliffe

--
https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor