Why there is a limitation that index operator can be applied as shortcut only for one-argument get? Is this ideological or technical limitation? It would be great to allow things like this:
a[b, c] => a.get(b, c)
a[b, c] = d => a.set(b, c, d)
DanielFathThu 22 Oct 2009
Well a[b] is just syntax sugar for a.get(b) And since fan doesn't support overloading of methods by parameters, you can't can have both get(b) and get(b,c) simultaneously.
Only way to allow it is to either make a.get2(b,c) for which the syntax sugar would be a[b,c] or use default operator like a.get(b, c:=null). The first option looks clunky and the second option is elegant until you get to setter.
IIRC only last parametar can be default leading to a.set(b, d, c:=null) which really looks garbled up.
That is about it.
Oh yeah they could make b,c to be a List[Int] but that only complicates the whole thing even further.
brianThu 22 Oct 2009
I think given Fan's C/Java/C# heritage, that indexing should just work with one argument. You can always use the get method if it has additional parameters, the [] sugar doesn't doesn't really save that many characters to make it worth the complication.
ivanThu 22 Oct 2009
Yes, I understand that there is no overloading by parameters and I didn't mean that some class should support both a[i] and a[i, j] simultaneously, so arg count is always fixed, but may differ for different classes. Also, regarding your second option - having set semantics like set(value, index1, index2 := null, ...) does not look garbled, but it is too big change, feature does not worth it I guess
ivan Thu 22 Oct 2009
Why there is a limitation that index operator can be applied as shortcut only for one-argument get? Is this ideological or technical limitation? It would be great to allow things like this:
DanielFath Thu 22 Oct 2009
Well
a[b]
is just syntax sugar fora.get(b)
And since fan doesn't support overloading of methods by parameters, you can't can have bothget(b)
andget(b,c)
simultaneously.Only way to allow it is to either make
a.get2(b,c)
for which the syntax sugar would bea[b,c]
or use default operator likea.get(b, c:=null)
. The first option looks clunky and the second option is elegant until you get to setter.IIRC only last parametar can be default leading to
a.set(b, d, c:=null)
which really looks garbled up.That is about it.
Oh yeah they could make b,c to be a
List[Int]
but that only complicates the whole thing even further.brian Thu 22 Oct 2009
I think given Fan's C/Java/C# heritage, that indexing should just work with one argument. You can always use the
get
method if it has additional parameters, the[]
sugar doesn't doesn't really save that many characters to make it worth the complication.ivan Thu 22 Oct 2009
Yes, I understand that there is no overloading by parameters and I didn't mean that some class should support both a[i] and a[i, j] simultaneously, so arg count is always fixed, but may differ for different classes. Also, regarding your second option - having set semantics like set(value, index1, index2 := null, ...) does not look garbled, but it is too big change, feature does not worth it I guess