On 10.09.2014 21:00, LesK wrote:> On 9/10/2014 1:20 PM, Rony wrote:
>> ..2014 19:04, LesK wrote:
>>> On 9/10/2014 6:41 AM, Rony wrote:
>>>> On 10.09.2014 02:11, Jeremy Nicoll - news posts wrote:
>>>>> LesK <
5mr...@tampabay.rr.com> wrote:
>>
>>
... snip ...
>> ---
>>
>> Besides, with the means ooRexx supplies in this context, you are free
>> to inspect the packages (required Rexx programs) for the current Rexx
>> program, add addtional packages to it and the like. Very flexible and
>> powerful.
>>
> In my scenario, I don't want other team members doing that! I want them to collaborate with each
> other and me and I will control the list.
>> ---rony
>>
>>
> I guess my explicit example didn't adequately explain the use of the word 'global', which is used
> throughout the ooRexx Reference document, so let me try again:
>
> If it were GLOBAL, then _only_ the top-level program would have to have
> a ::REQUIRES statement and all child programs would inherit the same statement WITHOUT MODIFICATION!
> Less work, less chance of error.
O.K., you asked for it. ;)
ooRexx allows you to get to this kind of functionality with this (a little bit) advanced technique:
do not call the Rexx programs directly, instead create routine objects of them and send the call
message to the routine object.
Here are three Rexx programs, "test.rex", "test2.rex", "test3.rex":
test.rex:
--------------------- test.rex ----------------
parse source . . thisName
say "--->"
thisName=filespec("Name",thisName)
say "arrived in:" thisName
-- show all routines defined in this Rexx program/package
do r over .routines
say thisName":" r
end
-- create a routine object for the given Rexx program
rexxPgmName="test2.rex"
r=lkg(rexxPgmName) -- returns the executable routine
r~call -- invoke "test2.rex"
say "<---"
-- Les Koehler Global: pass context (all required Rexx programs/packages) on
::routine lkg public
use strict arg rexxPgmName
say "in >>> LKG()! <<<"
rexxPgmCode=charin(rexxPgmName,1,chars(rexxPgmName)) -- string
return .routine~new(rexxPgmName,rexxPgmCode)
--------------------- test.rex ----------------
test2.rex:
--------------------- test2.rex ---------------
parse source . . thisName
thisName=filespec("Name",thisName)
tab="09"x
say tab "--->"
say tab "arrived in:" thisName
-- show all routines defined in this Rexx program/package
-- do r over .routines
do r over .context~package~routines
say tab r
end
call from_test2 tab
say tab "now creating a new routine on the fly:"
-- create a routine object for the given Rexx program
r=lkg("test3.rex")
r~call
-- create a routine on the fly
r=.routine~new("hi", "say '09'x 'hi (created in a single statement)'")
r~call
say tab "<---"
::routine from_test2
use arg tab
say tab "in routine" .context~name
--------------------- test2.rex ---------------
test3.rex:
--------------------- test3.rex ---------------
say ' >>> in test3.rex <<<'
--------------------- test3.rex ---------------
Running "test.rex" yields the following output:
--------------------- output ---------------
F:\test\koehler\lkg>test
--->
arrived in: test.rex
test.rex: LKG
in >>> LKG()! <<<
--->
arrived in: test2.rex
FROM_TEST2
in routine FROM_TEST2
now creating a new routine on the fly:
in >>> LKG()! <<<
>>> in test3.rex <<<
hi (created in a single statement)
<---
<---
--------------------- output ---------------
As you can see, "test2.rex" is able to access the routine LKG() in "test.rex".
Also, "test2.rex" demonstrates how to create a routine on the fly (dynamically)
---
It is actually easy to do stunts like these in ooRexx, granted, one needs to become aware of this
functionality which adds a tremendeous amount of flexibility to Rexx.
HTH,
---rony