Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.rexx

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-2012, 07:10 AM
Swifty
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

On Sat, 03 Mar 2012 19:22:10 -0500, Rick McGuire
<object.rexx@gmail.com> wrote:

>This question makes no sense to me.


I wrote an init.rex that requires init.sub

Init.sub contains:

Trace ?r
Say 'In init.sub'
If .local~init.var = .Nil then .local~init.var = time()

Init.rex contains:

Trace ?r
Say 'In init.rex'
Say .init.var
'start init.rex'
Say 'init.rex about to exit'


When I run init.rex, I see the code in init.sub running. When the
first instance of init.rex starts a second instance of init.rex, I see
the code in init.sub executing again.

So, presumably both instances loaded their own distinct instance of
"init.sub".

I think we should be careful to distinguish between the first load of
init.sub within the current rexx process and the more global "first
load of init.sub" (I don't think this concept has any significance,
practically speaking).

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 03-04-2012, 08:11 AM
LesK
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

Swifty wrote:
> On Sat, 03 Mar 2012 19:22:10 -0500, Rick McGuire
> <object.rexx@gmail.com> wrote:
>
>> This question makes no sense to me.

>
> I wrote an init.rex that requires init.sub
>
> Init.sub contains:
>
> Trace ?r
> Say 'In init.sub'
> If .local~init.var = .Nil then .local~init.var = time()
>
> Init.rex contains:
>
> Trace ?r
> Say 'In init.rex'
> Say .init.var
> 'start init.rex'
> Say 'init.rex about to exit'
>
>
> When I run init.rex, I see the code in init.sub running. When the
> first instance of init.rex starts a second instance of init.rex, I see
> the code in init.sub executing again.
>
> So, presumably both instances loaded their own distinct instance of
> "init.sub".
>
> I think we should be careful to distinguish between the first load of
> init.sub within the current rexx process and the more global "first
> load of init.sub" (I don't think this concept has any significance,
> practically speaking).
>

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

inita.rex
-- some code
::requires initsub.rex

initb.rex
-- some code
::requires initsub.rex

initsub.rex
--initialization code
::routine demo1 public

Then wouldn't you expect the initialization code to run only once?

--

Les (Change Arabic to Roman to email me)
Reply With Quote
  #3 (permalink)  
Old 03-04-2012, 09:49 AM
Rick McGuire
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

On 3/4/2012 4:11 AM, LesK wrote:
> Swifty wrote:
>> On Sat, 03 Mar 2012 19:22:10 -0500, Rick McGuire
>> <object.rexx@gmail.com> wrote:
>>
>>> This question makes no sense to me.

>>
>> I wrote an init.rex that requires init.sub
>>
>> Init.sub contains:
>>
>> Trace ?r
>> Say 'In init.sub'
>> If .local~init.var = .Nil then .local~init.var = time()
>>
>> Init.rex contains:
>>
>> Trace ?r
>> Say 'In init.rex'
>> Say .init.var
>> 'start init.rex'
>> Say 'init.rex about to exit'
>>
>>
>> When I run init.rex, I see the code in init.sub running. When the
>> first instance of init.rex starts a second instance of init.rex, I see
>> the code in init.sub executing again.
>> So, presumably both instances loaded their own distinct instance of
>> "init.sub".
>>
>> I think we should be careful to distinguish between the first load of
>> init.sub within the current rexx process and the more global "first
>> load of init.sub" (I don't think this concept has any significance,
>> practically speaking).
>>

> 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:


New process actually. But it's still a new instance of the interpreter.

>
> main.rex
> call inita
> call initb
> exit
>
> inita.rex
> -- some code
> ::requires initsub.rex
>
> initb.rex
> -- some code
> ::requires initsub.rex
>
> initsub.rex
> --initialization code
> ::routine demo1 public
>
> Then wouldn't you expect the initialization code to run only once?
>


Yes, you've got it. Note that prior to 4.0, each program required
initsub would load a new copy, so if you try this on an older version,
you'll see multiple calls to initsub. This was changed in 4.0 to have
centralized management of the loaded files so that this is done only once.

Rick

Reply With Quote
  #4 (permalink)  
Old 03-04-2012, 12:03 PM
Swifty
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

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.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Reply With Quote
  #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
  #6 (permalink)  
Old 03-04-2012, 01:56 PM
LesK
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

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.
>

Do I recall you're using Object Rexx, not ooRexx? If so, the 'one
initialization' improvement in ooRexx 4.0 wouldn't apply anyway. We're not
talking about reentrant assembler code :-)

--

Les (Change Arabic to Roman to email me)
Reply With Quote
  #7 (permalink)  
Old 03-04-2012, 06:08 PM
Swifty
Guest
 
Posts: n/a
Default Re: Using :requires to load some common routines

On Sun, 04 Mar 2012 09:56:39 -0500, LesK <5mre20@tampabay.rr.com>
wrote:

>Do I recall you're using Object Rexx, not ooRexx?


I use both. I cannot be bothered to upgrade the IBM Object REXX on my
work PC, but on our office Linux servers, we're on oorexx 4.0.1 at the
moment.

The Rexx on my PC is used mainly for simple command-line utilities, so
the IBM Object REXX has never needed to be updated.

I've updated oorexx (on our Linux) to correct bugs, but as of 4.1.1
Beta (as it stands now) my list of extant bugs is empty, so that is
likely to be the one that I bow out on.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 07:29 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.