Packages
Declarations may be stored in a package: once compiled, the package can be used by any model by means of the uses or import statements (see Section Directive uses). Except for its beginning and termination (keyword model is replaced by package) a package source is similar to a normal model source. The following points should be noticed:
- all statements and declarations outside procedure or function definitions are used as an initialization routine: they are automatically executed before statements of the model using the package;
- symbols that should be published by the package must be made explicitly public using the public qualifier (see Section The public qualifier);
- model parameters of a package are automatically added to the list of parameters of the model using the package;
- a package cannot be imported several times by a model and packages publish symbols of packages they import. For instance, assuming package P1 imports package P2, a model using P1 cannot import or use explicitly P2 but has access to the functionality of P2 via P1.
Version management
When a package defines a version number (see Section Directive version) Mosel implements a compatility rule similar to the one used for modules: a package version A can be used in place of package version B if major(A) = major(B) and minor(A) ≥ minor(B). This mechanism applies at compile time (when using different packages with the same dependencies) and at runtime when loading a model.
The requirements block
Requirements are symbols a package requires for its processing but does not define. These required symbols are declared in requirement blocks which are a special kind of declaration blocks in which constants are not allowed but procedure/functions can be declared. The symbols of such a block have to be defined when the model using the package is compiled: the definitions may appear either in the model or in another package but cannot come from a module. Several packages used by a given model may have the same requirements (i.e. same identifier and same declaration). It is also worth noting that a package inherits the requirements of the packages it uses.
requirements an_int:integer s0: set of string bigar: array(S0) of real procedure doit(i:integer) end-requirements
Control parameters
Packages may define control parameters that can be used just like those of modules via routines getparam and setparam. A control parameter is defined in the parameters block (see Section The parameters block) using the following syntax:
pname: type_name |
where pname is the name of the parameter as a constant string and type_name its type (either integer, real, string or boolean). In addition to this declaration accessor routines must be defined: for handling integer parameters the public function pkgname∼getiparam(pname:string):integer and the public procedure pkgname∼setparam(pname:string,v:integer) must be defined (pkgname being the name of the current package). The function will be called by getparam to retrieve the value of the specified parameter (as a string in lower case) and the procedure will be used by setparam to change the parameter value. Similar definitions will be required for the other types (assuming the package declares parameters of the corresponding types), namely getrparam (real parameters), getsparam (string parameters) and getbparam (Boolean parameters) as well as the associated procedures setparam. The following example shows the required definitions for the package mypkg to publish real parameters p1 and p2:
parameters "p1":real "p2":real end-parameters declarations myp1,myp2:real ! private variables to hold parameter values end-declarations ! get value function for real parameters public function mypkg~getrparam(p:string):real case p of "p1": returned:=myp1 "p2": returned:=myp2 end-case end-function ! set value procedure for real parameters public procedure mypkg~setparam(p:string,v:real) case p of "p1": myp1:=v "p2": myp2:=v end-case end-procedure
© 2001-2020 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.