1. Home
  2. CHECKARGUMENT procedure

CHECKARGUMENT procedure

Checks the arguments of a procedure (R.W. Payne).

Option

ERROR = scalar This scalar is given the value 1 if any errors are detected; it should have the value 0 on entry

Parameters

STRUCTURE = identifiers Lists the structures (arguments) to be checked
VALUES = variates or texts Defines the allowed values for a structure of type variate or text
DEFAULT = identifiers Default to be used if STRUCTURE is set to an unset dummy
SET = texts Indicates whether or not each structure must be set (no, yes); default no
DECLARED = texts Indicates whether or not each structure must have been declared (no, yes); default no
TYPE = texts Text for each structure whose values indicate the types allowed (scalar, factor, text, variate, matrix, diagonalmatrix, symmetricmatrix, table, expression, formula, dummy, pointer, LRV, SSPM, TSM); default *
PRESENT = texts Indicates whether or not each structure must have values (no, yes); default no

Description

This procedure can be used to check that each argument of a procedure is set, that it is set to a structure of a valid type, that the structure has values, and (for structures of type text or variate) that the values belong to a defined set; unset arguments can be assigned a default. The information about each argument is specified by the parameters of CHECKARGUMENT; if there is anything that is not to be checked, the corresponding parameter should be left unset. The scalar specified by the ERROR option is set to 1 if an error is discovered, and an explanatory message is printed; this scalar should be initialized to zero before calling CHECKARGUMENT.

Option: ERROR.

Parameters: STRUCTURE, VALUES, DEFAULT, SET, DECLARED, TYPE, PRESENT.

Method

CHECKARGUMENT uses GETATTRIBUTE to obtain details of the structures being checked, ASSIGN to set defaults, and if-blocks to make the various tests.

See also

Directives: OPTION, PARAMETER, PROCEDURE.

Commands for: Program control.

Example

CAPTION 'CHECKARGUMENT example'; STYLE=meta
VARIATE V[1...3]; VALUES=!(1.2,2.4),!(4.8),*
TEXT T[1...3]; VALUES=!T(a,c),!T(b),*
MATRIX [ROWS=1; COLUMNS=2; VALUES=1,2] M
POINTER P
TABLE Tb
LRV [ROWS=3; COLUMNS=3] L
DUMMY D[1...12]; VALUE=V[1...3],T[1...3],M,P,Tb,L,X,*
SCALAR E
CALCULATE E = 0
PRINT 'Here there are 12 arguments to check.'
CHECKARGUMENT [ERROR=E] D[1...12]; SET=11('yes'),'no';\
  TYPE=3('variate','text'),\ 
       !T(matrix,diagonalmatrix),'pointer','table','LRV',*,*; \
  DECLARED=10('yes'),2('no'); \
  VALUES=2(!(1.2,2.4,3.6,4.8,6)),*,2(!T(a,b,c,d,e)),7(*); \
  PRESENT=(2('yes'),'no')2,'yes',5('no')
PRINT 'No errors so E remains as 0.'
PRINT E
CALCULATE E = 0
PRINT 'Now illustrate various kinds of errors.'
CHECKARGUMENT [ERROR=E] D[12]; SET='yes'
PRINT E
CALCULATE E = 0
CHECKARGUMENT [ERROR=E] D[1]; SET='no'; TYPE=!t(scalar,text); DECLARED='no'
PRINT E
CALCULATE E = 0
CHECKARGUMENT [ERROR=E] D[11]; SET='no'; TYPE='variate'; DECLARED='yes'
PRINT E
CALCULATE E = 0
CHECKARGUMENT [ERROR=E] D[1]; SET='no'; TYPE='variate'; DECLARED='yes';\ 
  VALUES=!(1...6)
PRINT E
CALCULATE E = 0
CHECKARGUMENT [ERROR=E] D[4]; SET='no'; TYPE='text'; DECLARED='yes';\
  VALUES=!T(A,B,C,D,E)
PRINT E
CALCULATE E = 0
CHECKARGUMENT [ERROR=E] D[6]; SET='no'; TYPE='text'; DECLARED='yes';\
  VALUES=!T(A,B,C,D,E); PRESENT='yes'
PRINT E
Updated on March 8, 2019

Was this article helpful?