/* Test enhanced with private attributes */
DO i OVER .METHODS
SAY "Method:" i
END
SAY "attr_pub:" .object~enhanced(.METHODS)~attr_pub
SAY "attr_priv:" .object~enhanced(.METHODS)~attr_priv
EXIT
::ATTRIBUTE attr_pub GET PUBLIC
RETURN "pub"
::ATTRIBUTE attr_priv GET PRIVATE
RETURN "priv"
results in
Method: ATTR_PRIV
Method: ATTR_PUB
attr_pub: pub
9 *-* SAY "attr_priv:" .object~enhanced(.METHODS)~attr_priv
Error 97 running D:\BatCmd\enhanced.rex line 9: Object method not found
Error 97.1: Object "enhanced Object" does not understand message "ATTR_PRIV"
I can't see anything which says that this will only work with public methods. .METHODS clearly contains the private method, and it is all in the same file, so the difficulty lies elsewhere.
Anonymous
The problem is not with ~enhanced() but with what the example is trying to do. .object~enhanced(.METHODS) creates an object that has two attributes/methods. One is public and one is private. The private one can only be accessed from other methods of the same object, not from an "outside" user. As the Ref. says "A private method is like an internal subroutine." so this is working as expected.
So you are efffectively saying that private floating methods are unusable, and always will be?
Graham, this is not a bug. Private methods can only be invoked from specific calling contexts - for details see rexxref 4.2.8. Public and Private Methods.
Bug or not, if they can't ever be used, private floating methods are useless. What is a specific calling context which can be applied to them, if there is one?
Graham, please study the docs first, before drawing conclusions too early.
Why would one want to use a private floating method ?
Put the methods in a class and private become useful.
What are you trying to achieve ?
Rony, thank you for your comment.
hex, the example above is of course, not useful. What I want is a public floating attribute which references a private floating attribute, but I can't do that because private floating methods are apparently (and no-one has demonstrated that they aren't) unusable. The addition of package floating methods to 5.0 suggest that at some point this problem was recognised and addressed.
Graham, as Rick has pointed out that floating methods (method, attribute, constant directives that are not assigned to a class) are used in situations (and are quite handy) where one has a need to dynamically assemble classes and their methods under the programmer's control.
Your samples try out the concepts, but sometimes the assumptions or expectations do not match the sample.
Here you see a slightly changed version of your own program which uses private methods. So your conclusion, that floating private methods are useless does not hold.
If you run the program, this is its output: