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.expose type fvar hdr -- expose needed to access the object variables
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'assigned values. But the first SAY command displays "TYP HDR FVAR". Then, after the assignment statement, the second SAY displays "TYP Explanation FVAR".
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
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.
---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:
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
::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?
Expose makes the object variable available to the method (including INIT). With out the EXPOSE instruction, your INIT method is just assigning values to local variables that will go away once the method terminates.
--- On Wednesday, May 20, 2020 at 12:55:46 AM UTC-4, robhb...@gmail.com wrote:
...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
So without EXPOSE, an attribute's not visible to the methods IN THE SAME CLASS? Isn't that a little weird?
In that case what do PUBLIC and PRIVATE mean on an ::attribute? Oh, I guess only whether the attribute is available to the main program. Still weird.
Don't get me wrong, I love REXX - been using it for decades now - and I love oo programming, once I finally got the hang of it. So I expect to love ooRexx...once I get the hang of it :).
Ok, next question: My method now assigns values correctly, once I add the EXPOSE statement. But it doesn't seem to work for a constant:
::class C
::constant typs 'TESOV'
::method init
expose typs
say typs
When I create a new object of type C, it displays "TYPS"; the INIT method apparently can't see the constant. My main program can, though; when I ask it to SAY OBJ~TYPS it displays "TESOV". Same question, I guess; what am I missing? Notice Iattempted to use EXPOSE, but that apparently didn't do the job.
--- On Wednesday, May 20, 2020 at 6:24:03 AM UTC-4, Rick McGuire wrote:statement creates two methods, like this:
Expose makes the object variable available to the method (including INIT). With out the EXPOSE instruction, your INIT method is just assigning values to local variables that will go away once the method terminates.
--- On Wednesday, May 20, 2020 at 12:55:46 AM UTC-4, robhb...@gmail.com wrote:
...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
...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
::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 */
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 113 |
Nodes: | 8 (0 / 8) |
Uptime: | 178:12:23 |
Calls: | 2,506 |
Files: | 8,706 |
Messages: | 1,933,996 |