Re: Just `base`
Posted: Thu Jan 23, 2014 12:58 pm
nerdzero is correct.
Discussion about the Cobra programming language.
http://cobra-language.com/forums/
nerdzero wrote:@kirai84, interesting examples. I had to think about it for a bit, but if the intent is that "base" is just shorthand for the explicit call I would expect 'base.someMethod(1)' to be called in the first example and 'base.someMethod(2)' in the second example. Would that be right, Charles?
base(*) # or something else instead of '*'
kirai84 wrote:nerdzero wrote:@kirai84, interesting examples. I had to think about it for a bit, but if the intent is that "base" is just shorthand for the explicit call I would expect 'base.someMethod(1)' to be called in the first example and 'base.someMethod(2)' in the second example. Would that be right, Charles?
And what if you want to call a base method with default arguments in the first example? You could do it like this 'base()' or explicitly ('base.someMethod'), but it would be even more inconsistent and confusing.
class ClassA
var _ints = List<of int>()
def someMethod(i as int = 0)
_ints.add(i)
class ClassB inherits ClassA
def someMethod(i as int = 0) is override
base.someMethod # didn't pass the value of "i". didn't pass an alternate value. huhwhat?
class B inherits A
def someMethod(i as int = 0)
base # override call with caller args
.baser # method call with no options (huh?)
# longer arglist and shorthand more useful
def someMethod(i as int =0, s as String, val as GClass)
base.someMethod(i,s,val) # fully expressed
# vs
base(i,s,val)
# vs
base(*) # '*' as explicit notation meaning 'copy of calling args'
class A inherits B
def foo is override
# what does base call look like here, with no args?
class A inherits B
def foo is override
# what does base call look like here, with no args?
# either of
base.foo # as now (shorthand for base.foo() )
# or just
base # call the base overridden method ( no args)
# - shorthand for base.<what I'm in and overriding now>() - i.e base.foo()