Topic
  • 3 replies
  • Latest Post - ‏2013-01-15T08:52:14Z by JustAFreeName
JustAFreeName
JustAFreeName
10 Posts

Pinned topic PL/1: How can I specifiy a procedure with a variable number of parameters?

‏2013-01-11T14:27:18Z |
Hi!
 
Having a "C" background, I want to implement a procedure which I can call with a variable
number of parameters. In "C" you have a varargs.h
If my intention is unclear, maybe
helps understand my  question.
 
My compilation unit is a "package", and the procedure is using locally inside the package.
 
To give an example:
 
CALL  INIT_SET_OF_VALUES(VALUE1);
or
CALL INIT_SET_OF_VALUES(VALUE1, VALUE2, VALUE3);
 
I want to avoid a calls/definitions like
 
/* provide the number  of actual provided parameters */
CALL INIT_SET_OF_VALUES(n,  VALUE1, ... , VALUEn);
 
or
 
/* define the procedure for  a maximum number of params and provide always  
   as many parameters as defined. If less parameters are available a specific 
   "nullValue" is used to fillup the param list and 
    signal: this formal parameter has no actual value                  */ 
CALL INIT_SET_OF_VALUES(VALUE1, nullValue, nullValue);  
  
Questions: 
Q-1: Is there a way to do it (without using an assembler part to determine the # of params) 
Q-2: How to declare such a procedure? 
Q-3: How to pick the number of parameters provided 
 
I was not able to find a hint in the PL/1 manuals.
 
Regards, JustAFreeName  
 
Updated on 2013-01-15T08:52:14Z at 2013-01-15T08:52:14Z by JustAFreeName
  • Robin400
    Robin400
    33 Posts

    Re: PL/1: How can I specifiy a procedure with a variable number of parameters?

    ‏2013-01-14T02:17:51Z  
    Use the OPTIONAL attribute for parameters.
    For your scheme, the first parameter can be normal, and subsequent ones can be given
    the OPTIONAL attribute.
    Be sure to use the OMITTED built-in function in the subroutine/function before using an
    optional parameter.
  • Robin400
    Robin400
    33 Posts

    Re: PL/I: How can I specifiy a procedure with a variable number of parameters?

    ‏2013-01-14T04:12:30Z  
     Alternatively, you can use the GENERIC facility:
     
    declare SUB  generic (
      e1 when (*),
      e2 when (*, *),
      e3 when (*, *, *) );
    e1: procedure (p1); ...
    end;
    e2: procedure (p1, p2); ...
    end e2;
    e3: procedure (p1, p2, p3); ...
    end e3;
     
    Then you can use:
    call e1(a1);
    and
    call e2(a1, a2);
    and
    call e3(a1, a2, a3);
     
    The asterisks may be replaced by attributes, if required.
  • JustAFreeName
    JustAFreeName
    10 Posts

    Re: PL/1: How can I specifiy a procedure with a variable number of parameters?

    ‏2013-01-15T08:52:14Z  
    • Robin400
    • ‏2013-01-14T02:17:51Z
    Use the OPTIONAL attribute for parameters.
    For your scheme, the first parameter can be normal, and subsequent ones can be given
    the OPTIONAL attribute.
    Be sure to use the OMITTED built-in function in the subroutine/function before using an
    optional parameter.
     Hi Robin400.
     
    Thx for the reply and guideline. 
    I'll try the "OPTIONAL/ OMITTED" scheme.
     
    This scheme matches my visual perception in a prefect way
     
    Thx a lot!
    Regards, JustAFreeName.