r***@gmail.com
2020-05-20 04:55:45 UTC
I'm used to TSO (mainframe) REXX, but I'm also comfortable writing classes in VBA and VBS. So I figured ooRexx would be a pleasurable snap. Ok, so I have a lot more to learn than I expected.
I see in the documentation that the ::attribute directive ... well, I think it's equivalent to establishing a "property" in VBA. So I write a simple program like this:
opar=.par~new('E')
say opar~typ opar~hdr opar.fvar
opar~hdr="Explanation"
say opar~typ opar~hdr opar.fvar
exit
::class Par
::attribute typ --1 char
::attribute hdr --text
::attribute fvar --boolean
::method init
trace 'I'
arg typ
select
when typ='A' then do; fvar=0; hdr="Alpha"; end
when typ='E' then do; fvar=1; hdr='Explanation'; end
otherwise nop; end
What I expect is that ::attribute directives establsh three attributes of the Par object, and I will be able to get at them from the main program. When I run the program, the trace inside the INIT method shows that typ, hdr and fvar are indeed being assigned values. But the first SAY command displays "TYP HDR FVAR". Then, after the assignment statement, the second SAY displays "TYP Explanation FVAR".
So the ::attribute directive isn't accomplishing what I think the documentation says it should. And I'm suspicious of my reading anyway, because not one of the sample programs that came with ooRexx contain any ::attribute directives. Yet properties (as they're called in VBA) are so fundamental a part of classes that I figure I must be missing something basic.
---
Jumping to conclusions, here: Someone's going to say "You have to use EXPOSE or SELF~. I haven't figured out yet what SELF is for, but it says here EXPOSE makes variables available to methods, whereas what I want is the reverse, to make attributes available to the main program, ie the caller of the class. And anyway the documentation explicitly says that the ::attribute statement creates two methods, like this:
::method "NAME=" /* attribute set method */
expose name /* establish direct access to object variable (attribute) */
use arg name /* retrieve argument and assign it to the object variable */
::method name /* attribute get method */
expose name /* establish direct access to object variable (attribute) */
return name /* return object's current value */
What am I missing, please?
I see in the documentation that the ::attribute directive ... well, I think it's equivalent to establishing a "property" in VBA. So I write a simple program like this:
opar=.par~new('E')
say opar~typ opar~hdr opar.fvar
opar~hdr="Explanation"
say opar~typ opar~hdr opar.fvar
exit
::class Par
::attribute typ --1 char
::attribute hdr --text
::attribute fvar --boolean
::method init
trace 'I'
arg typ
select
when typ='A' then do; fvar=0; hdr="Alpha"; end
when typ='E' then do; fvar=1; hdr='Explanation'; end
otherwise nop; end
What I expect is that ::attribute directives establsh three attributes of the Par object, and I will be able to get at them from the main program. When I run the program, the trace inside the INIT method shows that typ, hdr and fvar are indeed being assigned values. But the first SAY command displays "TYP HDR FVAR". Then, after the assignment statement, the second SAY displays "TYP Explanation FVAR".
So the ::attribute directive isn't accomplishing what I think the documentation says it should. And I'm suspicious of my reading anyway, because not one of the sample programs that came with ooRexx contain any ::attribute directives. Yet properties (as they're called in VBA) are so fundamental a part of classes that I figure I must be missing something basic.
---
Jumping to conclusions, here: Someone's going to say "You have to use EXPOSE or SELF~. I haven't figured out yet what SELF is for, but it says here EXPOSE makes variables available to methods, whereas what I want is the reverse, to make attributes available to the main program, ie the caller of the class. And anyway the documentation explicitly says that the ::attribute statement creates two methods, like this:
::method "NAME=" /* attribute set method */
expose name /* establish direct access to object variable (attribute) */
use arg name /* retrieve argument and assign it to the object variable */
::method name /* attribute get method */
expose name /* establish direct access to object variable (attribute) */
return name /* return object's current value */
What am I missing, please?