@Serializable
abstract const class SerBase {
new make(|This|? f := null) {
f?.call(this)
...
}
new makeWith(Range scale) : this.make(|SerBase t| {t.scale = scale}) {}
which is a little ugly'n'verbose. Is there anyway to make the 2nd ctor use an it block, so it reads a little more like:
new makeWith(Range scale) : this.make({it.scale = scale}) {}
?
Steve.
brianWed 19 Dec 2012
I see what you mean, not sure about that though since I'm almost sure it would add a lot of extra complexity to the compiler for sort of a odd boundary condition (I don't think I've ever run across, anyone else?).
KevinKelleyWed 19 Dec 2012
Might be a good use for the static new constructor pattern -- since the awkwardness is in the normal style of constructor chaining, meaning that you have to force a bunch of syntax into that self-initializer.
static new fromRange(Range scale) { make { it.scale = scale} }
With normal new, the object is under construction when the constructor is called; with static new, you're in static scope and have wider control of the construction sequence.
SlimerDudeThu 20 Dec 2012
The static new would be a good idea, but it's an abstract class, so, err... :(
The chaining comes about from having the class Serializable - and the ctor generates a lots of transient data from a couple of seed parameters.
It's no biggie - I was just wondering if I'd missed any syntax. It seems not.
SlimerDude Wed 19 Dec 2012
Hi,
I have ctor's like this:
which is a little ugly'n'verbose. Is there anyway to make the 2nd ctor use an
it
block, so it reads a little more like:?
Steve.
brian Wed 19 Dec 2012
I see what you mean, not sure about that though since I'm almost sure it would add a lot of extra complexity to the compiler for sort of a odd boundary condition (I don't think I've ever run across, anyone else?).
KevinKelley Wed 19 Dec 2012
Might be a good use for the static new constructor pattern -- since the awkwardness is in the normal style of constructor chaining, meaning that you have to force a bunch of syntax into that self-initializer.
With normal
new
, the object is under construction when the constructor is called; withstatic new
, you're in static scope and have wider control of the construction sequence.SlimerDude Thu 20 Dec 2012
The
static new
would be a good idea, but it's an abstract class, so, err... :(The chaining comes about from having the class Serializable - and the ctor generates a lots of transient data from a couple of seed parameters.
It's no biggie - I was just wondering if I'd missed any syntax. It seems not.