use
use keyword imports an IRL package
or artifact.
Purpose
This keyword is used to import an IRL package or artifact.
Context
Packages
Syntax
use [packageName.] artifactName | packageName.*;
Description
The effect of referencing artifacts is different depending on whether they belong to the default package or not.
- Using an artifact from another package
To use an artifact from another package, write this statement if the artifact is a variable, rule, or task:
use artifactName;For functions, the syntax is more complex because you must uniquely identify the artifact that you want to import. To do so, include the function signature in the
usestatement:use displayPrice(double);- Referencing artifacts in the default package
To reference artifacts from the default package in package B, you can import the artifacts one by one (not necessarily all of them) from the default package, using the
usekeyword. Only these artifacts are visible in package B.When artifact names conflict, the following rule applies: If the default package defines an artifact named
artifactNameand package B defines an artifact also namedartifactNameand uses package A, all references toartifactNamein B are considered to be references to the B artifact and priority is given to the local artifact. There is no way to reference the artifact in the default package.- Referencing another package that is not the default
-
To reference artifacts from package A (A not being the default package) in package B, you can do one of the following:
You can write a
usestatement to import package A into package B. In this case, all its artifacts are visible in package B.If you can import artifacts from package A one by one (not necessarily all of them) uisng the
usekeyword. In this case, only the imported artifacts are visible in package B.
When artifact names conflict, the following rules apply:
If package A defines an artifact named
artifactNameand package B defines an artifact also namedartifactNameand uses package A, all references toartifactNamein package B are considered to be references to the B artifact and priority is given to the local artifact. To reference the A artifact, you must use its fully qualified name.If two packages A and B define an artifact named
artifactName, and if package C® uses packages A and B and references theartifactNameartifact, an error is raised because it is impossible to give priority to a package against another. To avoid any ambiguity, use the fully qualified name.
Example
This example defines two packages, pricing and europe.pricing.
The displayPrice function belongs to the default
package. The europe.pricing package uses the pricing package
and the displayPrice function.
function void displayPrice(double price)
{
...
}
package pricing
{
variables {
Customer customer;
}
rule isEligible
{
when {
...
}
then {
...
}
}
}
package europe.pricing
{
use pricing.*; All the pricing package is imported. All its artifacts are
visible in this package
use displayPrice(double); The function displayPrice from the default package
is imported
ruletask main
{
body {
isEligible
}
finalaction {
displayPrice(3.2d);
}
}
}