Single-element lists should require a trailing comma (maybe) #1179
Replies: 3 comments 1 reply
-
Yes.
Yes, the You can find the same effect in non-range examples, such as
Consider that we do want syntax like for (1, 2, 3) do (i) { } // ok
for (1, 2) do (i) { } // ok
for (1) do (i) { } // ok
for 1 do (i) { } // error, 1 is not a range So the status quo for a for (1, 2, 3) do (i) { } // ok
for 1 ..= 3 do (i) { } // ok, same meaning
for 1 ... 4 do (i) { } // ok, same meaning
(BTW so does Cpp2 now, thanks again to everyone who motivated me to finally add that.)
That's the kind of thing I would worry about. |
Beta Was this translation helpful? Give feedback.
-
Remind again, was there a reason not to use |
Beta Was this translation helpful? Give feedback.
-
It was a well reasoned choice though 😂 so yes, there were reasons, I was on the side of using [] initially, but I was converted, though it was a while ago so I don't remember specifics
On 2 August 2024 01:48:15 Andrew Sukach ***@***.***> wrote:
Just a choice made by Herb
—
Reply to this email directly, view it on GitHub<#1179 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AALUZQLGKPW5W7YLTXF76GDZPLJMZAVCNFSM6AAAAABLMZ3LFKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMRRG44DEMQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
From what I can tell,
iterates over a range of ints, 1 through 10, while
iterates over a list of
cpp2::range<int>
s, which is probably due to the fact that(0..=10)
gets treated as a single-element least.I, personally, find it a bit confusing. I would not expect that adding a pair of parenthesis around an expression fundamentally changes it. And while I know that cpp2 currently uses
(...)
instead of[...]
for lists, intuitively I do expect such behavior from[...]
, but not from(...)
.For example, in Python, there are essentially two types of lists commonly used. The
[...]
"lists" (variable-length, a-lastd::vector
1) and the(...)
"tuples" (fixed length, a-lastd::array
1). Python allows trailing commas (thankfully), but for single-element tuples it requires a trailing comma for disambiguation.So, should cpp2 do something similar?
Footnotes
Except of course Python allows storing elements of different types, because it is dynamically typed. Essentially it stores a vector/array of
object
s. ↩ ↩2Beta Was this translation helpful? Give feedback.
All reactions