Page 1 of 1

ReadOnly Field or Property

Posted: Fri Oct 03, 2008 8:06 pm
by paulmansour
Often I want a readonly public field that is set once and only once in the constructor. It seems the only to accomplish this is to make it propery, and define a getter function which simply returns the underlying private property. Is this correct? Any other way to do it? This takes a lot of boiler plate code. It seems that the constructor should allow the setting of read-only fields.

Re: ReadOnly Field or Property

Posted: Mon Oct 06, 2008 8:25 am
by StefanoLanzavecchia
Another way would be to allow (like in Ruby) the execution of code, let's say when the script is fixed, to build automatically those properties.

Re: ReadOnly Field or Property

Posted: Wed Oct 08, 2008 2:08 am
by paulmansour
Stefano, isn't that what happens now in a class in dyalog? It gets executed when fixed. The problem (for me) is that I want a read-only field instantiated when the instance is created, not when the class is created or fixed.

Re: ReadOnly Field or Property

Posted: Wed Oct 08, 2008 3:11 pm
by StefanoLanzavecchia
What I was suggesting was a way to obtain executing code the structure you proposed (i.e.: a property without the setter). The ":Property" in the script prevents this from happening and []FX'ing a function that ":implements" the property getter doesn't seem to work.

Re: ReadOnly Field or Property

Posted: Thu Oct 09, 2008 2:35 pm
by JohnD|Dyalog
StefanoLanzavecchia wrote:Another way would be to allow (like in Ruby) the execution of code, let's say when the script is fixed, to build automatically those properties.



And I believe (memory's not what it was, and I'm too busy to check), that you can assign to a readonly field at class fix time.

Re: ReadOnly Field or Property

Posted: Thu Oct 09, 2008 7:25 pm
by paulmansour
John, I hope so, otherwise how would a readonly field every get a value? ;)