Arrays as arguments 
Author Message
 Arrays as arguments

Hi, I'm just a beginner at REXX programming and
  I have a question: how do you pass arrays to
  a subroutine. I would like to do something like
  the following:

      a.1 = 'one'
      a.2 = 'two'
      call sub a.
      say a.1  ---> 'WHATEVER'
      say a.2  ---> 'SOMETHING'
      exit

      sub:
      parse arg array
      array.1 = 'WHATEVER'
      array.2 = 'SOMETHING'
      return

-Ted



Sun, 20 Sep 1998 03:00:00 GMT  
 Arrays as arguments

Quote:

>Hi, I'm just a beginner at REXX programming and
>  I have a question: how do you pass arrays to
>  a subroutine. I would like to do something like
>  the following:
>      a.1 = 'one'
>      a.2 = 'two'
>      call sub a.
>      say a.1  ---> 'WHATEVER'
>      say a.2  ---> 'SOMETHING'
>      exit
>      sub:
>      parse arg array
>      array.1 = 'WHATEVER'
>      array.2 = 'SOMETHING'
>      return
>-Ted

You can't, but you can fake in this way:

   line.0 = 3
   call sub 'line.'      /* Pass the name of the variable WITH the period */
   do i=1 to line.0; say line.i; end
   exit

/* This first sub is only used to pass the variable name to sub2
   which then can expose this variable. You could add code in this
   first sub to add the period to the variable name, if not there.
   If the variables in sub2 does not need to be hidden from the main
   program, sub2 can be used directly but without the procedure stmnt.
*/
sub:
   arg var .
   call sub2 var
   return

sub2: procedure expose (var)
   arg var
   number = 0
   t1 = value(var !! number)    /* Read 'line.0'. Variable t1 is not
                                   exposed and will not interfere with
                                   the main program. */
   do i=1 to t1    /* line.0 must have been set before in this example */
     interpret var !! i '=' something   /* Write to 'line.n' */
   end
return

Another way of using expose is to have a common stem (base) and
then passing the name of the tail to use to the sub.

   line='LINE'    /* Name of the "variable" without a period. */
   base.line.0 = 1
   base.line.1 = 'Hello'
   call sub line
   do i=1 to base.line.0; say base.line.i;end
   exit

sub: procedure expose base.
   arg var
   line = base.var.0    /* Variable line is not exposed and will not
                        interfere with the main program */
   line=line+1; base.var.line = 'all'
   line=line+1; base.var.line = 'REXX'
   line=line+1; base.var.line = 'hackers.'
   base.var.0 = line
return

Good luck,
Bo Siltberg



Mon, 21 Sep 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing array as argument to function

2. Array procedure arguments with undefined elements

3. allocatable array as argument

4. Allocatable arrays as arguments to subroutine questions

5. pass array as argument

6. arrays as arguments

7. arrays as argument to a proc ?

8. Possible to pass entire array as argument?

9. ARRAY as argument to exec?

10. Array as argument to proc

11. array section as actual argument where dummy argument is INTENT(OUT)

12. Detecting uninitialized subroutine argument used as array bound of another argument

 

 
Powered by phpBB® Forum Software