Previous Page Next Page Contents

testargs -- decide whether procedure arguments should be tested

Introduction

Inside a procedure, testargs indicates whether the procedure was called on the interactive level.

Call(s)

testargs()
testargs(b)

Parameters

b - TRUE or FALSE

Returns

TRUE or FALSE.

Related Functions

proc, testtype, Pref::typeCheck

Details

Example 1

The following example demonstrates how testargs should be used inside a procedure. The function p is to generate a sequence of n zeroes; its argument should be a positive integer:

>> p := proc(n)
   begin
      if testargs() then
          if not testtype(n, Type::PosInt) then
             error("expecting a positive integer");
          end_if;
      end_if;
      return(0 $ n)
   end_proc:

Its argument is checked when p is called on the interactive level:

>> p(13/2)
      Error: expecting a positive integer [p]

Calling p from within a procedure with an inappropriate parameter does not invoke the argument testing. The following error message is not issued by p. It is caused by the attempt to evaluate 0 $ n:

>> f := proc(n) begin p(n) end_proc: f(13/2)
      Error: Illegal argument [_seqgen];
      during evaluation of 'p'

We switch on the ``debugging mode'' of testargs:

>> testargs(TRUE):

Now also a non-interactive call to p produces an informative error message:

>> f(13/2)
      Error: expecting a positive integer [p]

We clean up, restoring the ``standard mode'' of testargs:

>> testargs(FALSE): delete f, g:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000