ReadOnly Field or Property

Writing and using Classes in Dyalog APL
Post Reply
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

ReadOnly Field or Property

Post 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.
User avatar
StefanoLanzavecchia
Posts: 113
Joined: Fri Oct 03, 2008 9:37 am

Re: ReadOnly Field or Property

Post 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.
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Re: ReadOnly Field or Property

Post 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.
User avatar
StefanoLanzavecchia
Posts: 113
Joined: Fri Oct 03, 2008 9:37 am

Re: ReadOnly Field or Property

Post 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.
User avatar
JohnD|Dyalog
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: ReadOnly Field or Property

Post 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.
paulmansour
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm

Re: ReadOnly Field or Property

Post by paulmansour »

John, I hope so, otherwise how would a readonly field every get a value? ;)
Post Reply