[Pythonic] Are empty tuple and array literals syntactically incompatible?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Pythonic] Are empty tuple and array literals syntactically incompatible?

Dirk Laurie-2
Would allowing empty tuple and array literals
   y = ()
   x = []
introduce an ambiguity?

Note: I am not asking about their semantics. It's all syntax.

Reply | Threaded
Open this post in threaded view
|

Re: [Pythonic] Are empty tuple and array literals syntactically incompatible?

Luiz Henrique de Figueiredo
>    x = []

x = [[1]] is already a string, not a nested tuple. Requiring x = [ [x]
] seems weird.

Reply | Threaded
Open this post in threaded view
|

Re: [Pythonic] Are empty tuple and array literals syntactically incompatible?

Jay Mithani


On Jul 6, 2018, at 6:35 AM, Luiz Henrique de Figueiredo <[hidden email]> wrote:

>>   x = []
>
> x = [[1]] is already a string, not a nested tuple. Requiring x = [ [x]
> ] seems weird.
>

In the statement x = [[]], the outer tuple is not empty. Therefore I do not think this presents a conflict.
Reply | Threaded
Open this post in threaded view
|

Re: [Pythonic] Are empty tuple and array literals syntactically incompatible?

Charles Heywood
Sure, but I think the question would more accurately be, "would allowing _any kind_ of these literals introduce an ambiguity", as this is a case that might not have been considered.

On Fri, Jul 6, 2018 at 12:31 PM Jay Mithani <[hidden email]> wrote:


On Jul 6, 2018, at 6:35 AM, Luiz Henrique de Figueiredo <[hidden email]> wrote:

>>   x = []
>
> x = [[1]] is already a string, not a nested tuple. Requiring x = [ [x]
> ] seems weird.
>

In the statement x = [[]], the outer tuple is not empty. Therefore I do not think this presents a conflict.
--
--
Ryan | Charles <[hidden email]>
Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: [Pythonic] Are empty tuple and array literals syntactically incompatible?

Axel Kittenberger
In reply to this post by Jay Mithani
In the statement x = [[]], the outer tuple is not empty. Therefore I do not think this presents a conflict.

As Luiz said, [[ ]] denotes already a (multiline) string constant in Lua.

So x would be an empty string, or the suggested array literal containing an empty array literal.
Reply | Threaded
Open this post in threaded view
|

Re: [Pythonic] Are empty tuple and array literals syntactically incompatible?

Sergey Zakharchenko
In reply to this post by Dirk Laurie-2

Dirk,

"Dirk Laurie" <[hidden email]>:
>
> Would allowing empty tuple and array literals
>    y = ()
>    x = []
> introduce an ambiguity?

I know I'm a bit slow but never saw the answer to your exact original question, so:

x=A[[]] becomes ambiguous (function call with empty string argument vs indexing with an empty tuple index)

If you treat () as {} and "", A() becomes ambiguous as well.

This is rather obvious so you must have found out by now, so sorry for the noise.

Best regards,

--
DoubleF