include a file

I tried to run your latest REXX entry (Rosetta code task: "include a file") and I got three different errors, one with Regina, another with R4, and also with Personnel REXX (all are the latest versions):

link to the Rosetta Code page:   ──►   [Include a file/REXX]


 
───────────────────────────────────────────────────────────────────09/12/2015 22:05:57
c:\►regina include
This is a program running.
     3 +++ if Open(other,'SYS:Rexxc/otherprogram.rexx','READ') then do
Error 40 running "c:\include.rex", line 3: Incorrect call to routine
Error 40.4: Too many arguments in invocation of "OPEN"; maximum expected is 2

───────────────────────────────────────────────────────────────────09/12/2015 22:06:04
c:\►r4 include
This is a program running.
Error 43 : Routine not found (or source program does not begin with a comment) (SYNTAX
)
Information: Could not find: Open  (or source file does not begin with a comment)
Error occurred in statement# 3
Statement source: if Open(other,'SYS:Rexxc/otherprogram.rexx','READ')
Statement context: c:\include.rex, procedure: include

───────────────────────────────────────────────────────────────────09/12/2015 22:06:12
c:\►type include.rex
/* Include a file and INTERPRET it; this code uses ARexx file IO BIFs */
say 'This is a program running.'
if Open(other,'SYS:Rexxc/otherprogram.rexx','READ') then do
   say "Now we opened a file with another chunk of code. Let's read it into a variabl"

   do until EOF(other)
      othercode=ReadLn(other) || ';'
      end
   call Close(other)
   say 'Now we run it as part of our program.'
   interpret othercode
   end
say 'The usual program resumes here.'
exit 0

───────────────────────────────────────────────────────────────────09/12/2015 22:07:14
c:\►rexx include.rex
This is a program running.
     3 +++ if Open(other,'SYS:Rexxc/otherprogram.rexx','READ')
Error 43 on line 3 of C:\INCLUDE.REX: Routine not found

───────────────────────────────────────────────────────────────────09/12/2015 22:10:46
c:\►

Is the REXX program expected to only be executed by a certain REXX interpreter or only under a certain operating system?   -- Gerard Schildberger (talk) 03:06, 13 September 2015 (UTC)

You need the ARexx BIFs and semantics (they're available in Regina) in order to use this Open syntax. I'm not familiar with any other REXX file I/O. --Idrougge (talk) 03:24, 13 September 2015 (UTC)
Then you'll need to include some sort of statement reflecting the needs of your REXX program so that it can be executed correctly.   You should probably also add a:     {{works|Regina with the option AREXX_BIFFS}} to the REXX section header.   You may also want to add that it ONLY works with Regina REXX.
It says so in the opening comment. And it also works with ARexx, from which Regina has inherited these BIFs. Not that it matters much, since it's a demonstration of INTERPRET rather than file I/O. --Idrougge (talk) 04:01, 13 September 2015 (UTC)
I did not (and can not) see where it states that the REXX program requires Regina REXX (or the AREXX REXX interpreter) and that it also requires a special Regina option to work.   This is what the {{works|xxx ...}} template is for, and it doesn't require the casual reader to delve into reading the opening comments within a program.   The same should be done with the first example:   add a {{works| CMS and TSO REXX compiler}}.   If you don't know how add that, I could insert the appropriate templetes so you can include them in the future.   -- Gerard Schildberger (talk) 04:17, 13 September 2015 (UTC)




Perhaps I'm doing something silly, but Regina REXX (3.9.1) is still giving me fits:


───────────────────────────────────────────────────────────────────09/12/2015 23:29:37
c:\►regina -oAREXX_BIFS include
This is a program running.
     3 +++ if Open(other,'SYS:Rexxc/otherprogram.rexx','READ') then do
Error 40 running "c:\include.rex", line 3: Incorrect call to routine
Error 40.4: Too many arguments in invocation of "OPEN"; maximum expected is 2

───────────────────────────────────────────────────────────────────09/12/2015 23:29:42
c:\►regina --options=AREXX_BIFS include
This is a program running.
     3 +++ if Open(other,'SYS:Rexxc/otherprogram.rexx','READ') then do
Error 40 running "c:\include.rex", line 3: Incorrect call to routine
Error 40.4: Too many arguments in invocation of "OPEN"; maximum expected is 2

───────────────────────────────────────────────────────────────────09/12/2015 23:29:57
c:\►r391 --options=AREXX_BIFS include
This is a program running.
     3 +++ if Open(other,'SYS:Rexxc/otherprogram.rexx','READ') then do
Error 40 running "c:\include.rex", line 3: Incorrect call to routine
Error 40.4: Too many arguments in invocation of "OPEN"; maximum expected is 2

───────────────────────────────────────────────────────────────────09/12/2015 23:32:47
c:\►

Is there something that I'm (easily) overlooking or am I doing something wrong but can't see it?

I also tried to run it with having the environmental variable REGINA_OPTIONS to have the AREXX_BIFS option included.   Still no joy.   -- Gerard Schildberger (talk) 04:30, 13 September 2015 (UTC)

Try this:

<lang rexx> /* Include a file and INTERPRET it; this code uses ARexx file IO BIFs */ OPTIONS AREXX_BIFS OPTIONS AREXX_SEMANTICS say 'This is a program running.' if Open(other,'other.rexx','READ') then do

  say "Now we opened a file with another chunk of code. Let's read it into a variabl"

othercode=

  do until EOF(other)
     othercode=othercode|| ReadLn(other) || ';'
     end
  call Close(other)
  say 'Now we run it as part of our program.'
  interpret othercode
  end

say 'The usual program resumes here.' exit 0 </lang>

--Idrougge (talk) 12:38, 13 September 2015 (UTC)




Thanks, that did the trick.   I never seen the AREXX_SEMANTICS Regina option before and it was a surprise to learn of it;   that particular option which is needed to make it execute properly was introduced in Regina REXX release 3.8.   It seems strange to me that when specifying the AREXX_BIFs option, you need another option to make use of some of those BIFs.   In any case, it would be a nice idea to include what Regina option(s) a user needs to run your Rosetta Code program without errors.

Why not just include the above options in the Rosetta Code REXX program to begin with?   Also nice would be an inclusion of the

{{works|REGINA 3.8 and later, with options: AREXX_BIFS and AREXX_SEMANTICS}}


statement.   -- Gerard Schildberger (talk) 18:24, 13 September 2015 (UTC)




My apologies:   I got the syntax wrong, it should be:

{{works with|REGINA 3.8 and later, with options: AREXX_BIFS and AREXX_SEMANTICS}}


-- Gerard Schildberger (talk) 20:39, 13 September 2015 (UTC)

local/global variables

In the Rosetta Code task   Include a file   where you mentioned:

  ... This means that including a file in your program is usually not necessary, unless you want them to share global variables.'

Did you mean to say   local   variables instead?

There are very few global variables:   RC, RESULT, and SIGL,   and those might not even be considered global   (Regina REXX has a few others as well).   Also, there are things like "ON" conditions, the settings for OPTIONS, TRACE, DIGITS, FORM, FUZZ, ADDRESS, and the like which may be considered global, at least in the sense that those values are carried forward into "lower levels" of subroutines/functions.   -- Gerard Schildberger (talk) 20:39, 13 September 2015 (UTC)

If you use AFunction: PROCEDURE, it has private variables. External programs called as functions are treated as PROCEDUREs, aren't they? --Idrougge (talk) 22:31, 13 September 2015 (UTC)
Return to the user page of "Idrougge".