Thanks to Rick for explaining the behavior (missing from the documentation) and Rony for his suggestions on workarounds.

I find that unfortunately, questions raised on the list are answered but the OP never responds, leaving one to wonder if 1) the answer solved the problem, 2) it didn't but the OP found another solution, or 3) the OP simply gave up.  In order to NOT follow that pattern, here is my result.  I was attempting to be able to run a program with a small modification - adding 2 lines to a ::routine within the program.  The simplest solution was copy the program, edit it to add the 2 lines, and run the modified program.  But that means I need to keep track of changes to the program (not written by me) so that I can keep my copy in sync.

The next easiest is to read the program into an array, search for the ::routine, add the 2 lines and write it to a file which can the be run.  As long as the basic structure of the program doesn't change, this works OK.  But I still have the "extra" file which I find unsatisfying.  So I tried a more dynamic approach which led to my original question.

My final solution is as follows.  Read the program into an array, append a line "::options noprolog", and create a package from that amended array using "thePkg = .package~new(pkgName, srce)", srce being the array.  Then I search the package for the routine and get its source using "theRtn = thePkg~findRoutine(rtnName)" and "rtnSrce = theRtn~source".  I can then append the 2 lines to rtnSrce and create a routine object using "newRtn = .routine~new(rtnName, rtnSrce, thePkg)--need context!".  A couple of points about that: the name of the new routine is the same as the old one and the third argument - the context - is essential. Then I add the new routine back to the package which replaces the old one with "thePkg~addRoutine(rtnName, newRtn)".  Finally, I can run the now modified program using the line suggested by Rony - "thePkg~prolog~call".

I am still dependent on the basic structure of the program not changing but I don't have any "extra" files being created. Hopefully this explanation will help someone in the future faced with a similar situation.

Gil

On 6/1/2024 10:38 AM, Rony G. Flatscher wrote:
On 31.05.2024 20:29, Gilbert Barmwater wrote:
I've been experimenting with the .package class and have run into somewhat puzzling behavior.  I am trying to create a .package object from a file which, according to the documentation, should look like this:

thePkg=.package~new(fileName)

When I do this I DO get a package in thePkg, BUT the package also gets loaded(executed) as if I had issued a
.context~package~loadPackage(fileName).

The docs do not indicate that this is to be expected.  Help!

If you do not want the prolog to be executed you can use "::options noprolog". Then later, whenever you want it to be executed you could issue "thePkg~prolog~call" or "thePkg~prolog~callWith(...)".

---rony




_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

--
Gil Barmwater



_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to