Initializing help system before first use

Parameters

In many cases, the actions to be performed by a procedure or the return value expected from a function depend on the current value of one or several objects in the calling program. It is therefore possible to pass parameters into a subroutine. The (list of) parameter(s) is added in parantheses behind the name of the subroutine:

 function times_two(b:integer):integer
  returned := 2*b
 end-function 

The structure of subroutines being very similar to the one of model, they may also include declarations sections for declaring local parameters that are only valid in the corresponding subroutine. It should be noted that such local parameters may mask global parameters within the scope of a subroutine, but they have no effect on the definition of the global parameter outside of the subroutine as is shown below in the extension of the example `Simple subroutines'. As in other programming languages, it is not possible to redefine function/procedure parameters in the corresponding subroutine (the declaration of local parameters must not hide these parameters). Mosel considers this as a mistake and prints an error message during compilation.

model "Simple subroutines"

 declarations
  a:integer
 end-declarations

 function three:integer
  returned := 3
 end-function

 function times_two(b:integer):integer
  returned := 2*b
 end-function

 procedure print_start
  writeln("The program starts here.")
 end-procedure

 procedure hide_a_1
  declarations
   a: integer
  end-declarations

  a:=7
  writeln("Procedure hide_a_1: a = ", a)
 end-procedure

 procedure hide_a_2(a:integer)
  writeln("Procedure hide_a_2: a = ", a)
 end-procedure

 procedure hide_a_3(a:integer)
  declarations
   a: integer
  end-declarations

  a := 15
  writeln("Procedure hide_a_3: a = ", a)
 end-procedure

 print_start
 a:=three
 writeln("a = ", a)
 a:=times_two(a)
 writeln("a = ", a)
 hide_a_1
 writeln("a = ", a)
 hide_a_2(-10)
 writeln("a = ", a)
 hide_a_3(a)
 writeln("a = ", a)

end-model 

During the compilation we get the error

Mosel: E-165 at (34,4) of `subrout.mos': Declaration of `a' hides a parameter.

This is due to the redefinition of a that is passed as an argument into procedure hide_a_3 and also appears in the declarations of this subroutine. We need to modify the definition of this procedure to correct this error, for example by renaming the subroutine argument:

 procedure hide_a_3(aa:integer) 

The program then results in the following output:

The program starts here.
a = 3
a = 6
Procedure hide_a_1: a = 7
a = 6
Procedure hide_a_2: a = -10
a = 6
Procedure hide_a_3: a = 15
a = 6

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.