[Swift-devel] app syntax ambiguity

Ben Clifford benc at hawaga.org.uk
Sun Dec 16 12:15:23 CST 2007



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[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.

-- 



More information about the Swift-devel mailing list