VMS Help  —  PASCAL  Declaration Section, Routine Declaration
  The basic algorithm for a program can usually  be  divided  into
  relatively  simple,  repetitive  tasks.  In Pascal, you can code
  each task  separately  as  a  routine;  that  is,  as  either  a
  procedure  or  a  function.   A  procedure  contains one or more
  statements to be executed  once  the  procedure  is  called.   A
  function contains one or more statements to be executed once the
  function is called;  in  addition,  functions  return  a  single
  value.

  A routine call executes  all  statements  in  the  body  of  the
  declared  routine.   You  must  declare a routine before you can
  call it.  In addition, function calls  return  a  single  value.
  Syntactically,  procedure  calls  are  statements,  and function
  calls are expressions.  You can call routines in the  executable
  section of a program or in the body of another routine.

  Syntax:

     [[attribute-list]]
     PROCEDURE routine-identifier [[formal-parameter-list]];
        { [[declaration-section]] BEGIN {statement};... END |
           {EXTERN
            EXTERNAL
            FORTRAN
            FORWARD} }

  Syntax:

     [[attribute-list]]
     FUNCTION routine-identifier [[formal-parameter-list]]
        : [[attribute-list]] result-type-id;
        { [[declaration-section]] BEGIN {statement};... END |
           {EXTERN
            EXTERNAL
            FORTRAN
            FORWARD} }

  The 'attribute-list' is one or more  optional  identifiers  that
  provide additional information about the type-denoter.

  The 'routine-identifier' is the name of the routine.  If you use
  the   routine-identifier  within  the  routine  body  (with  the
  exception of assigning a value to the  routine-identifier  of  a
  function),  the  result is a recursive call to the routine.  The
  routine-identifier of a  procedure  can  be  redeclared  in  the
  procedure's  declaration-section.   The  routine-identifier of a
  function   cannot    be    redeclared    in    the    function's
  declaration-section; however, it can be redeclared in any nested
  routines within the function's declaration-section.

  The 'formal-parameter-list' is a comma  list  of  the  routine's
  formal  parameters.   A procedure can have as many as 255 formal
  parameters;  depending  on  the  function  return  value,   some
  functions are limited to 254 formal parameters.  Optionally, you
  can specify a mechanism specifier and an attribute list for each
  parameter.

  The 'declaration-section' can include  all  sections  except  TO
  BEGIN DO, TO END DO, and VALUE sections.  Data specified in this
  declaration section is local to the routine and  to  any  nested
  routines;  you can redeclare identifiers that are declared in an
  outer block.  You cannot redeclare a formal parameter identifier
  to be a local variable in the routine.

  The 'statement' is any VSI  Pascal  statement.   In  a  function
  executable  section, there must be at least one statement of the
  following form:

     routine-identifier := result

  The 'routine-identifier' is the name of the function.

  The 'result' is a value of either an ordinal, real,  structured,
  or pointer type that VAX Pascal returns when function is called.
  This value must be of the same type as the  result-type-id,  and
  cannot  be  a  file  type  or  a  structured  type  with  a file
  component.

  'EXTERN', 'EXTERNAL', 'FORTRAN', and 'FORWARD'  are  predeclared
  identifiers  that  direct  VSI  Pascal  to  find the body of the
  routine  elsewhere.    The   EXTERN,   EXTERNAL,   and   FORTRAN
  identifiers  declare routines that are independently compiled by
  VSI Pascal or that are  written  in  other  languages.   In  VSI
  Pascal,  these identifiers are equivalent.  Although not part of
  the Pascal standard,  many  Pascal  compilers  only  accept  the
  FORTRAN  identifier  for  external  routines actually written in
  FORTRAN; if portability is  a  concern,  you  may  wish  to  use
  FORTRAN only for external FORTRAN routines.

  The 'result-type-id' is the type specification of  the  function
  return  value.  The function's result must be of this data type.
  This type cannot be a file type or a structured type with a file
  component.

  Example:

     PROCEDURE Read_Write( VAR A : INTEGER );

  This  declares  a  procedure,  'Read_Write',  which  takes   one
  variable parameter, 'A'.

  Example:

     FUNCTION Counter( VAR Instring, Outstring : VARYING[10] OF CHAR;
                       VAR Valid : Boolean ) : INTEGER;

  This declares a function, 'Counter', which takes three  variable
  parameters,  'Instring', 'Outstring', and 'Valid' and returns an
  INTEGER value.
Additional Information: explode extract

formal_parameter_list
block
directive
Close Help