I've added a new ticket (ticket:178) for the enhancement of providing support for nested or inner classes.
Does anyone have any comments or discussion points to make around this area ?
e.g
utility/desire/need ?
Whether its worthwhile to support java like semantics ( automatic access to instance methods/variables in enclosing class) or C# like behaviour
(specific coding idiom for same access)
Other?
...
There will probably be a patch for a simple implementation posted shortly
Forums
Nested (or inner) classes
8 posts
• Page 1 of 1
Re: Nested (or inner) classes
I thought Java like == inner class, C# like == nested class.
- helium
- Posts: 14
Re: Nested (or inner) classes
Maybe some code examples in all three languages would be helpful. Compare and contrast Java vs. C# and then propose syntax and semantics for Cobra.
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Nested (or inner) classes
C# vs java differences C# nested classes are ike C++ nested classes, not Java inner classes.
simple cobra looks pretty much as you'd expect ;
something like this
simple cobra looks pretty much as you'd expect ;
something like this
- Code: Select all
# simple nested class - access from inside
class Enclosing
class Nested
cue init
base.init
def geti as int
return 1
def geti as int
return 99
def main
a = Enclosing()
assert a.geti == 99
n=Enclosing.Nested()
assert n.geti == 1
# slightly more involved
# multiple levels of Nested class, inferred and explicit typing
class Enclosing
class Nested is public
def geti as int
return 1
class Nested2
def geti as int
return 2
class NestedOther
get geti
return 10
def geti as int
return 99
class Enc
def main
a = Enclosing()
assert a.geti == 99
en=Enclosing.Nested()
assert en.geti == 1
enn=Enclosing.Nested.Nested2()
assert enn.geti == 2
eno as Enclosing.NestedOther?
eno = Enclosing.NestedOther()
assert eno.geti == 10
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
Re: Nested (or inner) classes
That's a handy link including the comments. Thanks.
Looks good to me.
The _boxStack you see in the Cobra compiler is there to support nested classes / structs. So you can see I tried to account for them even though I didn't have time to really do them.
-Chuck
Looks good to me.
The _boxStack you see in the Cobra compiler is there to support nested classes / structs. So you can see I tried to account for them even though I didn't have time to really do them.
-Chuck
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: Nested (or inner) classes
Yah - I posted a patch for the simplest implementation against the ticket.
It uses .curBox which used _boxStack ( cleaned out the TODO comment)
It uses .curBox which used _boxStack ( cleaned out the TODO comment)
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 51 guests