Hmm, I don't think the default args for Fantom are going to change anytime soon! (For that would make the rules for what is and isn't allow far too complicated.)
I don't really understand the problem - defaults are just a lazy way of specifying an argument, similar to method overloading in Java. The calling method could specify your default:
SetTag("name", Str#, myObj) ...
Or if your tuple always has a type you could write your own "defaults" impl:
Void SetTag(Str name, Obj p1 := null, Obj p2 := null) {
Type t := Str#
Obj value := null
if (p1 is Type) {
t = p1 as Type
value = p2
}
if (p2 is Type) {
t = p2 as Type
}
... wotever ...
Tags[name] = Tupla(t, value)
}
XanThu 8 Mar 2012
Thanks but I need (Str, Type, Obj) with Str# as Type as defaults. The simplest method is to define
SetTextTag(name,value) as SetTag(name, Str#, value)
but I wonder if I could have the same name. Why in fantom we not be able to have the same name for different slots with different arguments?
Thanks, Xan.
brianThu 8 Mar 2012
I'm not sure why if you want default arguments, you don't just put them at the end of the parameter list. This is expected paradigm for most languages, and is definitely the Fantom convention. I personally would expect your API to look like this:
setTag(Str name, Obj val, Type type := val.typeof)
SlimerDudeFri 9 Mar 2012
Why in fantom we not be able to have the same name for different slots with different arguments?
Xan Thu 8 Mar 2012
Hi,
I want to do something like this:
and compiler says me
Why I can't have one default argument and not passing default argument?
Thanks, Xan.
SlimerDude Thu 8 Mar 2012
Only the last arguments can have default values:
which makes complete sense, for if any arg could be default and you had a method like:
and you wrote
the compiler wouldn't know which args to assign values to! (a,c or b,c?)
Xan Thu 8 Mar 2012
Mmmm... okay, but for me the order is important. Not in this case but in others. I explain: I have
I want value1 as default value of a.
I could reverse order, but know I want a
I can't put the same name (Duplicate slot name). So I'm in trouble
For the other hand, the code of Fantom could change for allowing default args in left if there is only one default argument.
My real problem is that:
and Tupla only contains "Type" and "Obj" fields.
What can I do if I want "Type = Str#" as default?
Thanks in advance, Xan.
SlimerDude Thu 8 Mar 2012
Hmm, I don't think the default args for Fantom are going to change anytime soon! (For that would make the rules for what is and isn't allow far too complicated.)
I don't really understand the problem - defaults are just a lazy way of specifying an argument, similar to method overloading in Java. The calling method could specify your default:
Or if your tuple always has a type you could write your own "defaults" impl:
Xan Thu 8 Mar 2012
Thanks but I need (Str, Type, Obj) with Str# as Type as defaults. The simplest method is to define
but I wonder if I could have the same name. Why in fantom we not be able to have the same name for different slots with different arguments?
Thanks, Xan.
brian Thu 8 Mar 2012
I'm not sure why if you want default arguments, you don't just put them at the end of the parameter list. This is expected paradigm for most languages, and is definitely the Fantom convention. I personally would expect your API to look like this:
SlimerDude Fri 9 Mar 2012
See Method overloading
I think the last comment sums it up nicely :