[Swift-devel] app syntax ambiguity
Mihael Hategan
hategan at mcs.anl.gov
Sun Dec 16 14:43:25 CST 2007
On Sun, 2007-12-16 at 18:15 +0000, Ben Clifford wrote:
>
> On Sun, 16 Dec 2007, Mihael Hategan wrote:
>
> > Or both? As in multidimensional arrays are arrays of arrays. What we
> > want, I'm guessing, is the possibility to easily pass i[1] as an array
> > parameter instead of using something like i[i, *].
>
> That's how it looks like it works out anyway. You can already say
>
> [ [ "foo", "bar" ], ["one", "two", "three" ]]
>
> in the language at the moment - the type system isn't expressive enough to
> represent what the type of the above expression (an array of arrays of
> strings) but the appropriate DSHandle is constructed if you put the above
> in a program (because there's no type checking on array construction).
>
> I think you get what I meant by the ambiguity, though, here:
I didn't. But I do now.
>
> >> i[1][2] might mean two parameters i[1] and an array literal [2] or it
> >> might mean one parameter accessing a multidimensional array i[1][2].
>
> If i was the above, then i[1][2] might be "bar" (a string), or it might be
> two expressions:
> the array with two strings
> ["foo", "bar"]
> and then an array with one integer member
> [ 2 ]
>
> In practice, I guess, the greedy-from-the-left way of parsing seems to
> work in all the cases that anyone has come across so far so I'll probably
> leave it.
So let's be clear. This only applies to app{} blocks, right?
The syntax is somewhat ambiguous there. But the least surprise in the
context in which our multi-dimensional arrays are accessed as a[i][j]...
is for i[1][2] to mean i[1, 2]. I think the distinction can be made
based on whitespace between ']' and '['. I.e. i[1][2] vs. i[1] [2].
>
More information about the Swift-devel
mailing list