Mailing List Archive

walrus with a twist :+= or ...
I realized that the person seeking completeness in Python may next ask why
the Walrus operator, :=, is not properly extended to include a whole
assortment of allowed assignment operators



I mean in normal python programs you are allowed to abbreviate



x = x + 5



with



x += 5



Similarly you have other operators like



x *= 2



And, of course, the constantly used operator:



x %= 2



So how does one extend a walrus operator if they ever decide to give in and
add it to the language just for completeness?



Sadly, a simple test shows they neglected to use a :+= operator in the
latest:



>>> (walrus := 2)

2

>>> walrus

2

>>> (wallrus :+= 2)

File "<stdin>", line 1

(wallrus :+= 2)

^

SyntaxError: invalid syntax



(Yes, I know how to spell walrus, but making a point.)



On a serious note, if it was ever considered a good idea, what would be an
acceptable sequence of symbols that might not break or confuse existing
programs and what would we call it? I mean what animal, of course.



What do these look like in some fonts? :+= :-= :*= :/= :%=



Or do we not just add a colon in front and make it a tad different as in :=+
or :+=: or maybe realize the futility of perfection! After all, you can
easily use some functions to get a result such as:



x := func(x, "+", 5)

x := func_add(x, 5)



or many other work-arounds.



Can we all forget I asked? I am sort of being sarcastic.



--
https://mail.python.org/mailman/listinfo/python-list
RE: walrus with a twist :+= or ... [ In reply to ]
I just realized I left out **= so my apologies. Are there other such
abbreviations and does anyone use them?

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Avi Gross via Python-list
Sent: Wednesday, October 27, 2021 8:57 PM
To: python-list@python.org
Subject: walrus with a twist :+= or ...

I realized that the person seeking completeness in Python may next ask why
the Walrus operator, :=, is not properly extended to include a whole
assortment of allowed assignment operators



I mean in normal python programs you are allowed to abbreviate



x = x + 5



with



x += 5



Similarly you have other operators like



x *= 2



And, of course, the constantly used operator:



x %= 2



So how does one extend a walrus operator if they ever decide to give in and
add it to the language just for completeness?



Sadly, a simple test shows they neglected to use a :+= operator in the
latest:



>>> (walrus := 2)

2

>>> walrus

2

>>> (wallrus :+= 2)

File "<stdin>", line 1

(wallrus :+= 2)

^

SyntaxError: invalid syntax



(Yes, I know how to spell walrus, but making a point.)



On a serious note, if it was ever considered a good idea, what would be an
acceptable sequence of symbols that might not break or confuse existing
programs and what would we call it? I mean what animal, of course.



What do these look like in some fonts? :+= :-= :*= :/= :%=



Or do we not just add a colon in front and make it a tad different as in :=+
or :+=: or maybe realize the futility of perfection! After all, you can
easily use some functions to get a result such as:



x := func(x, "+", 5)

x := func_add(x, 5)



or many other work-arounds.



Can we all forget I asked? I am sort of being sarcastic.



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

--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
On Thu, Oct 28, 2021 at 11:58 AM Avi Gross via Python-list
<python-list@python.org> wrote:
> On a serious note, if it was ever considered a good idea, what would be an
> acceptable sequence of symbols that might not break or confuse existing
> programs and what would we call it? I mean what animal, of course.
>
>
>
> What do these look like in some fonts? :+= :-= :*= :/= :%=
>

What we need is a few more generic operators that can be put together
appropriately. For instance, when you need a copy of a list, you can
use the "robot face" operator:

stuff[:]

Perhaps we need some more slice variants. We can already grin:

stuff[
:D
]

and stick out our tongues:

stuff[
:P
]

and even gasp in surprise:

stuff[
:O
]

but the language has an emotional bias towards sadness:

stuff[
:(
)]

since there's no corresponding happiness emoji, nor even ambivalence:

stuff[
:|
]

However, a wry smile is permitted.

stuff[
:\
]

The lack of language support for such a fundamental emotion as
happiness is a major flaw and needs to be corrected ASAP.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
On 2021-10-28 02:06, Avi Gross via Python-list wrote:
> I just realized I left out **= so my apologies. Are there other such
> abbreviations and does anyone use them?
>
You forgot about the bitwise operators: |= &= ^=

> -----Original Message-----
> From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
> Behalf Of Avi Gross via Python-list
> Sent: Wednesday, October 27, 2021 8:57 PM
> To: python-list@python.org
> Subject: walrus with a twist :+= or ...
>
> I realized that the person seeking completeness in Python may next ask why
> the Walrus operator, :=, is not properly extended to include a whole
> assortment of allowed assignment operators
>
>
> I mean in normal python programs you are allowed to abbreviate
>
> x = x + 5
>
> with
>
> x += 5
>
> Similarly you have other operators like
>
> x *= 2
>
> And, of course, the constantly used operator:
>
> x %= 2
>
> So how does one extend a walrus operator if they ever decide to give in and
> add it to the language just for completeness?
>
> Sadly, a simple test shows they neglected to use a :+= operator in the
> latest:
>
>>>> (walrus := 2)
>
> 2
>
>>>> walrus
>
> 2
>
>>>> (wallrus :+= 2)
>
> File "<stdin>", line 1
>
> (wallrus :+= 2)
>
> ^
>
> SyntaxError: invalid syntax
>
> (Yes, I know how to spell walrus, but making a point.)
>
> On a serious note, if it was ever considered a good idea, what would be an
> acceptable sequence of symbols that might not break or confuse existing
> programs and what would we call it? I mean what animal, of course.
>
> What do these look like in some fonts? :+= :-= :*= :/= :%=
>
> Or do we not just add a colon in front and make it a tad different as in :=+
> or :+=: or maybe realize the futility of perfection! After all, you can
> easily use some functions to get a result such as:
>
> x := func(x, "+", 5)
>
> x := func_add(x, 5)
>
> or many other work-arounds.
>
> Can we all forget I asked? I am sort of being sarcastic.
>
--
https://mail.python.org/mailman/listinfo/python-list
RE: walrus with a twist :+= or ... [ In reply to ]
My apologies, again. I got Chris going and although quite humorous, we may
want to allow a slew of emoticons!

But a serious question is now that we sort of have UNICODE, and even many
editors and other programs support it, perhaps it might make sense for some
operations in computer languages to make use of them. Some languages might
replace something like <- with an arrow symbol and those with special
symbols like Inf might use the infinity symbol instead. More importantly,
adding new operators might get easier. Some existing languages like APL used
overstrikes to create some symbols. Some languages have a built-in extension
method such as R that allows you to create arbitrary functions by placing
them between % signs as in %>% or %percentile%

If Python wanted to add more flexibility than admittedly it already has,
then possibly something like I jokingly suggested as a walrus version of :=
might be doable by just defining some new function bound to a symbol which,
when run, is told of the operands on either side.

But dreaming aside, from an academician and programmer as well as a lazy bum
side of me, it is often perhaps easiest to design a new language practically
from scratch with ideas that it completely follow the paradigms you want.
SCALA is an example among others. Both a strength and weakness in Python as
it has grown is that it does so many things in so many ways as more and more
is grafted on. The relatively few existing symbols are overloaded too much
so it takes some context to figure out when a : or parenthesis or even %
sign means one of multiple things. The recent discussion sort of highlighted
how a comma meaning multiple things may be confusing. if we extend a
feature.

One reasonable design might be to expand the allowed symbols and use them as
needed. A colon might be used only one way. If you need a :: operator, it
can be a single token and a single character, perhaps clearly having the two
parts closer together or one part slightly raised or lowered. A += and >=
operator may again be the one symbol version so that + and = always mean the
same thing.

But it is a tad too late to make an existing language or users on existing
keyboards, do this. A language course I am using makes compromises so using
a partial pop-up keyboard lets me select characters with special twists like
an umlaut rather than showing a plain U or perhaps a :U instead of ? or
allowing an SS to be typed instead of ?. When used on character-only
scenarios, obviously you let the users mis-spell these ways but that is not
an ideal way to learn a language or write in it.

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Chris Angelico
Sent: Wednesday, October 27, 2021 9:11 PM
To: Python <python-list@python.org>
Subject: Re: walrus with a twist :+= or ...

On Thu, Oct 28, 2021 at 11:58 AM Avi Gross via Python-list
<python-list@python.org> wrote:
> On a serious note, if it was ever considered a good idea, what would
> be an acceptable sequence of symbols that might not break or confuse
> existing programs and what would we call it? I mean what animal, of
course.
>
>
>
> What do these look like in some fonts? :+= :-= :*= :/= :%=
>

What we need is a few more generic operators that can be put together
appropriately. For instance, when you need a copy of a list, you can use the
"robot face" operator:

stuff[:]

Perhaps we need some more slice variants. We can already grin:

stuff[
:D
]

and stick out our tongues:

stuff[
:P
]

and even gasp in surprise:

stuff[
:O
]

but the language has an emotional bias towards sadness:

stuff[
:(
)]

since there's no corresponding happiness emoji, nor even ambivalence:

stuff[
:|
]

However, a wry smile is permitted.

stuff[
:\
]

The lack of language support for such a fundamental emotion as happiness is
a major flaw and needs to be corrected ASAP.

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

--
https://mail.python.org/mailman/listinfo/python-list
RE: walrus with a twist :+= or ... [ In reply to ]
Correct, I left out a bit, not wisely.

I am trying to remember the last time (outside of classes) I have ever had
to use bitwise operators nontrivially and it may have been around 1980 when
I had to implement an encryption algorithm. Of course, when I was working in
UNIX, I often had to combine bitwise things to specify all kinds on 1-bit
flags when say opening a file.

So we now have so many candidates FOR COMPLETENESS to add as variants of the
Walrus operator, that I might vote to do NONE of them, if anyone ever asked.

I do want to remind people though that these operators often serve a purpose
in Python as using them means you do not need to specify an argument twice
and you can specify some dunder methods that make it more efficient to type:

obj += obj2

rather than

obj = obj + obj2

So there may be a valid argument, not just about completeness, to implement
something BUT as we got along fine before a walrus came along, ...

or did we?


-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of MRAB
Sent: Wednesday, October 27, 2021 9:21 PM
To: python-list@python.org
Subject: Re: walrus with a twist :+= or ...

On 2021-10-28 02:06, Avi Gross via Python-list wrote:
> I just realized I left out **= so my apologies. Are there other such
> abbreviations and does anyone use them?
>
You forgot about the bitwise operators: |= &= ^=

> -----Original Message-----
> From: Python-list
> <python-list-bounces+avigross=verizon.net@python.org> On Behalf Of Avi
> Gross via Python-list
> Sent: Wednesday, October 27, 2021 8:57 PM
> To: python-list@python.org
> Subject: walrus with a twist :+= or ...
>
> I realized that the person seeking completeness in Python may next ask
> why the Walrus operator, :=, is not properly extended to include a
> whole assortment of allowed assignment operators
>
>
> I mean in normal python programs you are allowed to abbreviate
>
> x = x + 5
>
> with
>
> x += 5
>
> Similarly you have other operators like
>
> x *= 2
>
> And, of course, the constantly used operator:
>
> x %= 2
>
> So how does one extend a walrus operator if they ever decide to give
> in and add it to the language just for completeness?
>
> Sadly, a simple test shows they neglected to use a :+= operator in the
> latest:
>
>>>> (walrus := 2)
>
> 2
>
>>>> walrus
>
> 2
>
>>>> (wallrus :+= 2)
>
> File "<stdin>", line 1
>
> (wallrus :+= 2)
>
> ^
>
> SyntaxError: invalid syntax
>
> (Yes, I know how to spell walrus, but making a point.)
>
> On a serious note, if it was ever considered a good idea, what would
> be an acceptable sequence of symbols that might not break or confuse
> existing programs and what would we call it? I mean what animal, of
course.
>
> What do these look like in some fonts? :+= :-= :*= :/= :%=
>
> Or do we not just add a colon in front and make it a tad different as in
:=+
> or :+=: or maybe realize the futility of perfection! After all, you can
> easily use some functions to get a result such as:
>
> x := func(x, "+", 5)
>
> x := func_add(x, 5)
>
> or many other work-arounds.
>
> Can we all forget I asked? I am sort of being sarcastic.
>
--
https://mail.python.org/mailman/listinfo/python-list

--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
The proposal is very interesting, my only concern is readability
unless a team has a tool check and flag it out as a process.

Else i fear one day i'll be seeing =+_+= in Python code.

But jokes aside @Avi why would someone want to immediately add a 2
after walrus defining it? in :+=2

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://www.pythonkitchen.com>
github <https://github.com/Abdur-RahmaanJ>
Mauritius
--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
On 2021-10-27 22:15:09 -0400, Avi Gross via Python-list wrote:
> But a serious question is now that we sort of have UNICODE, and even many
> editors and other programs support it, perhaps it might make sense for some
> operations in computer languages to make use of them.

I have thought so since the 1990's.

But while the large variety of unicode symbols is great for displaying
programs, it is awful for entering them. Keyboards have a limited number
of keys (and those are fairly standardized, if a different standard in
each country), so you either have to combine several keys or need to
pick characters by a different method (e.g. the mouse). Both are
cumbersome, shift the attention of the programmer from the algorithm to
the mechanics of entry, and are different from editor to editor.

I sometimes use Greek letters in variable names. But I do that only for
personal projects, not at work. I can't expect my co-workers to find out
how enter Greek letters in PyCharm or Visual Studio Code or Notepad++ or
whatever they are using and I don't want to do that research myself (I
know how to use digraphs im vim, thank you). And we are a small team.
Think of the diversity in a large multi-national company ...

It might work if the language is tightly integrated with an IDE. Then
the designers of the IDE and the designers of the language can work
together to make it easy to edit programs. And everyone who uses the
language has to use the IDE anyway (because of the tight integration),
so "but how do I type that in Notepad++?" is not a concern.

But tying together a language to an IDE that tightly will turn away all
programmers who are already used to a different IDE (or just plain
editor) and want to continue to use that.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
RE: walrus with a twist :+= or ... [ In reply to ]
Good points, Peter.

Although we are discussing Python, I think it would be reasonable to look a
bit more broadly.

Ages ago, IBM used a different encoding than ASCII called EBCDIC (Extended
Binary Coded Decimal Interchange Code ) which let them use all 8 bits and
thus add additional symbols. ? ? ?

So if you chose a specific set of symbols as a subset of UNICODE and
declared it to be PROGRAMMER symbols, it might be possible to provide
special keyboards that had something like the numeric keypad with a few more
symbols or in the place where the F1 keys are or wherever. All programming
languages that wished to use the symbols might be expected to mainly, or
exclusively, only use these symbols for unary or binary operators or other
purposes.

Look at one of the annoyances in Python (and similar in other languages)
where the matched symbols that come in left and right versions are overused.
() is used in oodles of contexts. So is {} and []. We do not use <> as
matching pairs because of other meanings. So a python dictionary and a
python set use the same general notation but can be disambiguated by the
contents sometimes.

And I note that single and double quotes are currently unique while other
programs like WORD make them in pairs with a clear open and close quote
slanted differently. Would we be better able to write clear constructs if
our programs also clearly marked beginning and ends of text in some
contexts, perhaps allowing even things like nested text?

I have no idea of details here and clearly too many symbols is as bad as too
few. I have taken lots of courses in topics like mathematics and physics
where I was bombarded by all kinds of notations and symbols that forced me
to learn the Greek and other alphabets so I could sort of pronounce them in
my mind, as well as funny "script" letters and all kinds of invented symbols
including many you now find in a wingding section. So having an assortment
of these be the same as used by programmers might be good for others. Think
not just Greek letters that would also give you pi, but the Integral sign
the symbol used for partial derivatives and of course you need an aleph from
Hebrew :=)

Is there a reasonable extension to a keyboard that might be reasonable,
perhaps with an accommodation to those without such a keyboard so that
entering some sequence gets it converted into what you want on the screen
but more mnemonic than 0X234f ??

Now once there was some sort of standard developed, all IDE for all
languages might have the option to adopt it. Of course, some symbols would
not be used or allowed in a particular language, albeit if they were all
otherwise valid UNICODE symbols, would be allowed in other contexts such as
within text or perhaps in variable names.

But back to python, I am not suggesting that it would be wise to modify much
of what exists even if this was available. Sets and Dictionaries might
remain as is, or there might be a second optional way to use them with new
symbols.

I happen to be one of the people who reads/writes/speaks in multiple
languages. Many decades ago I was forced to switch encodings carefully to
say ISO-8859-1 (Latin 1) if I wanted to write properly in German but
Hungarian required ISO 8859-2 and Hebrew needed ISO 8859-8 and Japanese
needed others like Shift JIS. For a while, much of my work included being
able to take in text and perform conversions and it was a royal pain. If
everyone used a small set of common encoding, as in UNICODE, things get
easier from one perspective. What I am suggesting is not as drastic but that
we choose a set of symbols that are clear and unambiguous and not huge but
larger than what we have now and gradually migrate to using more of it.
Obviously brand new languages could be designed to use it and existing
languages MIGHT use it more for new features and extensions.

So anyone know if anything like I am describing (or something much better)
is being looked at?



-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Peter J. Holzer
Sent: Thursday, October 28, 2021 5:08 AM
To: python-list@python.org
Subject: Re: walrus with a twist :+= or ...

On 2021-10-27 22:15:09 -0400, Avi Gross via Python-list wrote:
> But a serious question is now that we sort of have UNICODE, and even
> many editors and other programs support it, perhaps it might make
> sense for some operations in computer languages to make use of them.

I have thought so since the 1990's.

But while the large variety of unicode symbols is great for displaying
programs, it is awful for entering them. Keyboards have a limited number of
keys (and those are fairly standardized, if a different standard in each
country), so you either have to combine several keys or need to pick
characters by a different method (e.g. the mouse). Both are cumbersome,
shift the attention of the programmer from the algorithm to the mechanics of
entry, and are different from editor to editor.

I sometimes use Greek letters in variable names. But I do that only for
personal projects, not at work. I can't expect my co-workers to find out how
enter Greek letters in PyCharm or Visual Studio Code or Notepad++ or
whatever they are using and I don't want to do that research myself (I know
how to use digraphs im vim, thank you). And we are a small team.
Think of the diversity in a large multi-national company ...

It might work if the language is tightly integrated with an IDE. Then the
designers of the IDE and the designers of the language can work together to
make it easy to edit programs. And everyone who uses the language has to use
the IDE anyway (because of the tight integration), so "but how do I type
that in Notepad++?" is not a concern.

But tying together a language to an IDE that tightly will turn away all
programmers who are already used to a different IDE (or just plain
editor) and want to continue to use that.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"

--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
On Fri, Oct 29, 2021 at 5:53 AM Avi Gross via Python-list
<python-list@python.org> wrote:
> Is there a reasonable extension to a keyboard that might be reasonable,
> perhaps with an accommodation to those without such a keyboard so that
> entering some sequence gets it converted into what you want on the screen
> but more mnemonic than 0X234f ??

It's called Compose key sequences and they're supported by every
X11-based system, plus Windows and Mac OS if you set them up.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
RE: walrus with a twist :+= or ... [ In reply to ]
Thank, Chris. I found and installed one from here: https://github.com/samhocevar/wincompose

My right ALT key now lets me type in all kinds of nonsense like ? and © and ß and ?0 and ? and ? and ? and ?and although :- makes ÷ I see := makes ? which is just a longer equals sign.


Not sure this mailing list allows this stuff, so if your mailer does not show it, never mind.

Now I have to locate the list of available sequences as the built-in does not show many I want to se and I have already guessed some!

And, yes, as long as the list of additional program symbols is easily available, that should do even on standard keyboards.

?

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On Behalf Of Chris Angelico
Sent: Thursday, October 28, 2021 3:24 PM
To: Python <python-list@python.org>
Subject: Re: walrus with a twist :+= or ...

On Fri, Oct 29, 2021 at 5:53 AM Avi Gross via Python-list <python-list@python.org> wrote:
> Is there a reasonable extension to a keyboard that might be
> reasonable, perhaps with an accommodation to those without such a
> keyboard so that entering some sequence gets it converted into what
> you want on the screen but more mnemonic than 0X234f ??

It's called Compose key sequences and they're supported by every X11-based system, plus Windows and Mac OS if you set them up.

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

--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
On 2021-10-28, Avi Gross via Python-list <python-list@python.org> wrote:

> I see := makes ? which is just a longer equals sign.

On my screen it's an assignment operator that looks like := only a bit
smaller.

> Not sure this mailing list allows this stuff, so if your mailer does
> not show it, never mind.

Everything renders fine for me.
--
https://mail.python.org/mailman/listinfo/python-list
Re: walrus with a twist :+= or ... [ In reply to ]
On 2021-10-28 19:48:06 -0400, Avi Gross via Python-list wrote:
> My right ALT key now lets me type in all kinds of nonsense like ? and
> © and ß and ?0 and ? and ? and ? and ?and although :- makes ÷ I see
> := makes ? which is just a longer equals sign.

Ah, yes. That's another problem with using a large number of characters:
Some of them will be visually very similar, especially with monospaced
fonts.

I'm not getting any younger and with my preferred font (which is quite
small) I already have to squint to distinguish between : and ; or
between () and {}.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"