On Tue, 15 Mar 2022 at 00:07, Joao S. O. Bueno <jsbu...@python.org.br> wrote:
>
>
>
> On Mon, Mar 14, 2022 at 9:49 AM Chris Angelico <ros...@gmail.com> wrote:
>>
>> On Mon, 14 Mar 2022 at 23:35, <joao.p.f.batista...@gmail.com> wrote:
>> >
>> > Currently:
>> > l = [] # new empty list
>> > t = () # new empty tuple
>> > s = set() # new empty set (no clean and consistent way of initializing 
>> > regarding the others) <<<
>> > d = {} # new empty dictionary
>> >
>> > Possible solution:
>> > s = {} # new empty set
>> > d = {:} # new empty dictionary (the ":" is a reference to key-value pairs)
>>
>> Nope, that would break tons of existing code. Not gonna happen.
>
> Of couse not. (And I mean it).
> - but what about keeping what exists and adding {,}  for an empty set?
> (it is not that unlike the one-element tuple, which already exists)

That's more plausible. However, the one-element tuple is actually
written like this:

t = x,

The parentheses are a common form of clarity (and included in the
repr), but aren't actually the part of the syntax that makes it a
tuple - the comma is. So there's no real parallel, and it's basically
"what can we write that wouldn't be ambiguous?", which is a weak
justification.

Unfortunately, Python simply doesn't have enough symbols available.
Using precisely one opener/closer for each type is highly limiting,
since the only characters available are those on a US-English keyboard
and in the ASCII set. It would be nice if, for instance, ∅ could mean
"new empty set", but then we'd need a way to type it, and it'd end up
coming right back around to "just type set(), it's easier".

I wonder what it would be like to have a fork of Python that
introduces some non-ASCII non-US-English syntax, purely to give people
a chance to play around with it. Someone might actually set up an
editor feature so that "set()" transforms into "∅", not just visually
but in the file, and since it's restricted to an input feature in the
editor, it avoids the usual problems of "what if you shadow the name
set". Who knows? Maybe it would catch on, maybe it wouldn't.

It's not all that difficult to hack on Python and add this feature. I
did it a while back, but since I didn't use sets enough to bother
figuring out an input method, didn't end up using it. If you want to
write it as a pure source-code transformation, {*()} is a syntax-only
way to generate an empty set, so it'll guarantee that you don't run
into name shadowing issues; but it would be better to make it actual
syntax (and thus avoid unpacking a tuple into your set for no reason),
and also change the repr accordingly.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NYNTWQKJM4NOC72UPHVTUOUFCECYMZNW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to