View Single Post
  #5 (permalink)  
Old 03-04-2012, 12:10 PM
Rony
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

On 04.03.2012 14:03, Swifty wrote:
> On Sun, 04 Mar 2012 04:11:30 -0500, LesK <5mre20@tampabay.rr.com>
> wrote:
>
>> Doesn't START start a new thread? If you want to replicate what the discussion
>> was about, wouldn't you have to do something like:
>>
>> main.rex
>> call inita
>> call initb
>> exit

>
> As I read the thread there was no mention of the use of "call". And no
> one had distinguished between a "call" (which would stay within the
> existing rexx process) and something that starts a new process.
>
> We had also discussed the "first load of the required program" without
> mentioning the scope of "first".
>
> Since these sorts of actions run right to the heart of all the code
> that I've written in the past few years, I wanted to clarify when the
> statements about "first loaded" would be true, and when they were not
> true.
>
> For a horrific few minutes, I was wondering if the required program
> was loaded into memory shared across separate REXX processes, and the
> initialisation code ran only once.
>
> I don't mind separate processes sharing the same loaded code, but
> having the initialisation run only in the first process which required
> it would drive a coach and horses through most of my code.


Maybe a few remarks:

- if a ::requires statement is encountered, then Rexx checks, whether the denoted Rexx program
("package") was already required or not

leg 1: not yet required: in this case the interpreters does effectively "call" the denoted Rexx
program on your behalf, and afterwards remembers which routines and classes were defined to be public

leg 2: already required: in this case the interpreter merely makes the public routines and public
classes available to the requiring program (i.e. no call keyword statement will be carried out by
the interpreter)


This way, if all programs only use "::requires", the interpreter is able to make sure that the
required Rexx program/package gets executed only once, no matter how many times it gets required.

HTH,

---rony

P.S.: Just to point at another implication: if you explicitly call some Rexx program/package that
defines classes multiple times, then each time a call is carried out will cause all the classes to
be created from scratch. This means that there will be new class objects (which represent the
classes and maintain the inventory of methods etc.) created each time a call is carried out.

Using instead a "::requires" directive in all programs makes sure, that only one set of class object
gets created and shared among all requiring Rexx programs.





Reply With Quote