2. The Utilities Library
Namespace: model://perspectives.domains#Utilities
.
2.1. GenSym
GenSym()
Generate a random symbol.
callExternal util:GenSym() returns String
Parameter/Result | Type | Explanation |
---|---|---|
result (functional) |
String |
A random string. |
2.2. RoleIdentifier
<roleExpression> >> RoleIdentifier()
RoleIdentifier(role)
Returns the internal identifier of a role instance.
callExternal util:RoleIdentifier( Visitor ) returns String
Parameter/Result | Type | Explanation |
---|---|---|
role |
RoleInstance |
An instance of a role. |
result (functional) |
RoleIdentifier |
An identifier like "def:#defe6263_7ebf_43d1_ae9d_25d3f8146d05". |
2.3. ContextIdentifier
<contextExpression> >> ContextIdentifier()
ContextIdentifier( <context> )
Returns the internal identifier of a context instance.
callExternal util:ContextIdentifier( Chat ) returns String
Parameter/Result | Type | Explanation |
---|---|---|
context |
ContextInstance |
An instance of a context. |
result (functional) |
ContextIdentifier |
An identifier like "def:#defe6263_7ebf_43d1_ae9d_25d3f8146d05". |
2.4. SystemIdentifier
systemIdentifier()
Returns the string that identifies a particular installation. It is not a Resource Identifier (it doesn’t have a storage scheme prepended, e.g. "def:#blablabla" - it is just "blablabla")
Parameter/Result | Type | Explanation |
---|---|---|
result (functional) |
String |
The raw identifier of the installation. The ID of the PerspectivesSystem instance is constructed from it. |
callExternal util:SystemIdentifier() returns String
2.5. Replace
<valueExpression> >> Replace( <target>, <replacement> ) returns String
Replace( <target>, <replacement>, <value> ) returns String
Replace parts of a string with another string.
Parameter/Result | Type | Explanation |
---|---|---|
target |
String |
A literal string to find and replace in the value. |
replacement |
String |
A string to replace the matches with. |
value |
String |
The string value in which the replacement takes place. |
result (functional) |
String |
The string with the replacement. |
callExternal util:Replace( ".", "_", Repositories$NameSpace ) returns String
2.6. ReplaceR
<valueExpression> >> ReplaceR( <pattern>, <replacement> ) returns String
ReplaceR( <pattern>, <replacement>, <value> ) returns String
Replace parts of a string with another string.
Parameter/Result | Type | Explanation |
---|---|---|
pattern |
Regular expression |
A regular expression in string form, like the parameter of the Javascript RegExp object. |
replacement |
String |
A string to replace the matches with. |
value |
String |
The string value in which the replacement takes place. |
result (functional) |
String |
The string with the replacement. |
callExternal util:ReplaceR( "\\$.*$", "NewName", Repositories$NameSpace ) returns String
Note
|
to use a character class like \n in a regular expression, escape the backslash (\) character with another backslash, like this: \\n. |
2.7. SelectR
<valueExpression> >> SelectR( <pattern> ) returns String
SelectR( <pattern>, <value> ) returns String
Select part of a string.
Parameter/Result | Type | Explanation |
---|---|---|
pattern |
Regular expression |
A regular expression in string form, like the parameter of the Javascript RegExp object. |
value |
String |
The string value to select from. |
result (functional) |
String |
The selected substring. |
callExternal util:SelectR( "#(.*)", Repositories$NameSpace ) returns String
Note
|
to use a character class like \n in a regular expression, escape the backslash (\) character with another backslash, like this: \\n. |
2.8. Random
<numberExpression> >> Random( <lowerBound> ) returns Number
Random( <lowerBound>, <upperBound> ) returns Number
Returns a random integer between lower- and upperbound.
Parameter/Result | Type | Explanation |
---|---|---|
lowerBound |
Integer |
|
upperBound |
Integer |
|
result (functional) |
String |
Result will be a random integer uniformly distributed in the closed interval |
callExternal util:Random( "1", "10" ) returns Number
2.9. FormatDateTime
<stringExpression> >> FormatDateTime( <date>, <locale> ) returns String
FormatDateTime( <date>, <locale>, <options> ) returns Number
Format a date.
Parameter/Result | Type | Explanation |
---|---|---|
date |
DateTime |
A DateTime Value(see below). |
locale |
String |
A locale according to the [specification], e.g. "en-EN" or "nl-NL". |
options |
String |
This should be the serialisation of a JSON object: all identifiers and string are required to be in double quotes and these quotes must be escaped by a backslash to prevent breaking the surrounding string. |
result (functional) |
String |
A string that shows the date (and optionally time) in the required format. |
DateTime (PDate) values can be entered literally in Perspectives Language, or can be entered through the user interface, or can be read from the system clock (see the Sensor library, device "clock", sensor "now"). For the form of the literal representation see DateTime String Format on MDN. Summary: the type must conform to YYYY-MM-DDTHH:mm:ss.sssZ, but time may be left out.
The options object may contain any key-value pairs as specified in this ECMA specification.
For a discussion of the locale
and the options
object, see DateTimeFormat on MDN.
callExternal util:FormatDateTime( SomeDate, "nl-NL", "{\"dateStyle\": \"full\", \"timeStyle\": \"short\"}" ) returns Number
2.10. EvalExpression
<roleExpression> >> EvalExpression( <expression> ) returns String
EvalExpression( <expression>, <role> ) returns String
Parse, compile and evaluate an expression with respect to a particular role instance.
Parameter/Result | Type | Explanation |
---|---|---|
expression |
String |
A Perspectives Language query expression such as can be used in models for calculated properties. |
role |
roleInstance |
A role instance. |
result (unknown) |
String |
A string representation of the result of the query, whatever its Range type is. |
callExternal util:EvalExpression( "1 + 3" ) returns Number callExternal util:EvalExpression( TotalNumberOfItems / 5 ) returns Number