Catalog of built-in functions

all : string → object collection

all name

This returns all instances of the metaclass named name. For example, all "Class" returns all instances of the metaclass Class.

alternation : string x string → string

|=> : string x string → string

alternation (str, alt) ≡ str |=> alt ≡ if str <> "" then str else alt

If str is not the empty string, then this returns str; otherwise, returns alt.

   alternation ("abc", "def") ⇒ abc
   alternation ("", "def") ⇒ def
attribute : string x objectstring
$ : string x object → string
attribute (name, obj) 

This returns the value of the attribute named name of obj. If the metaclass of obj does not have an attribute named name, signals an execution error. The first parameter to $ is not enclosed in quotation marks, however, the first parameter to attribute is enclosed in double quotes.

The function always returns the value of an attribute as a string. Attributes in the metamodel, however, can be of other types—integer, real, boolean, and various enumerations. But attribute always returns a string because it is the safest assumption to make, given that the type object encompasses instances of all metaclasses. In essence, the type object is untyped with respect to the metamodel. Although a string value is always returned, no information is lost. The returned string can always be converted to the appropriate type, using one of the conversion operators. The only exception occurs with attributes that are enumerations. Enumerations are treated like strings, with the values being the textual names of the enumerators that make up an enumeration.

   attribute ("name", aClass) ≡ $name of aClass ⇒ Tree
   attribute ("type", anOperation) ⇒ std::string
   $name ≡ $name of current ⇒ Leaf
   boolean $isAbstract of aClass ⇒ true

attribute : string x object collection → string

$: string x object collection → string

attribute (name, ocoll) ≡ $name of ocoll ≡ comma map {$name} over ocoll

This returns a string formed from the values of the attribute named name of each object in ocoll, with the values separated by commas. If ocoll contains no objects, an empty string is returned. If ocoll contains just one object, say obj, then attribute(name, ocoll) is equivalent to attribute (name, obj). If the metaclass of an object in ocoll does not have an attribute named name, an execution error is generated.

   attribute ("name", all "Class") ⇒ Tree, Branch, Leaf
   attribute ("type", all "Operation") ⇒ grow
   $name of all "Class" ⇒ Tree, Branch, Leaf

class : object → string

class obj

This returns the name of the metaclass of obj.

   class aClass ⇒ Class
   class model ⇒ Model

comma : string collection → string

comma scoll

This returns the concatenation of all the strings in scoll, with the strings separated by commas.

concat : string collection → string

concat scoll

This returns the concatenation of all the strings in scoll.

find : regexp x string → string

find (re, s)

This returns the first substring of s that matches the regular expression re. If there is no substring of s that matches re, an empty string is returned (λ). When matching substrings, the maximum number of characters is matched.

   find ('[01]+', "---010111--111") ⇒ 010111
   find ('[a-z]+', "--010111") ⇒ λ

first : object collection → object

first ocoll

This returns the first object in ocoll. If ocoll is empty, an execution error is shown.

   $name of first all "Class" ⇒ Node

match : regexp x string → boolean

match (re, s) ≡ s ~= re

This returns true if, and only if, there is a substring of s that matches the regular expression re.

   match ('[01]+', "abc010111def") ⇒ true
   match ('^[01]+$', "abc010111def") ⇒ false
   match ('[01]*', "abc") ⇒ true

Note how this last example is true even though it would seem otherwise. The match succeeds because the closure * admits the empty string and because the empty string is a valid substring of "abc."

object : object collection → object

object ocoll ≡ only ocoll

See the entry for function only: object collection Æ object (below).

only : object collection → object

only ocoll

This returns the first and only object in ocoll. If ocoll is empty or has more than one object, then this signals an execution error.

   $name of only all "Class" ⇒ Node

replace : regexp x string x string → string

replace (re, s, r)

This returns a string equal to s with the first substring matching re replaced with r. If there is no substring of s that matches re, then returns s. When matching substrings, the maximum number of characters is matched.

replace ('[01]+', "---010111--111", "A") ⇒ ---A--111
replace ('[a-z]+', "010111", "A") ⇒ 010111

replace_all : regexp x string x string → string

replace_all (re, s, r)

This returns a string equal to s with all substrings matching re replaced with r. If there is no substring of s that matches re, then returns s. When matching substrings, the maximum number of characters is matched.

replace_all ('[01]+', "---010111--111", "A") ⇒ ---A--A
replace_all ('[a-z]+', "010111", "A") ⇒ 010111

The following example illustrates the use of "%s" with the replace_all keyword.

The replace_all command is also useful in reformatting a comma-separated list from a paragraph format into a column listing of the items. This usage of the command changes commas into spaces and inserts a new line (\n) to create the list:

replace_all (',',comma map {$name + "\n") over 
([containedElements]{$metaClass="[metaclass name]"})," ")

reverse : object collection → object collection

reverse ocoll

This returns the collection ocoll with the elements in reverse order.

$name of (all "Class") ⇒ "Class_0, Class_1, Class_2"
$name of (reverse all "Class") ⇒ "Class_2, Class_1, Class_0"

size : object collection → string

size ocoll

This returns the number of objects in ocoll.

   size all "Class" ⇒ 27

tolower : string → string

tolower s

This returns the string s with uppercase letters changed to lower case.

   tolower "aBcDeF" ⇒ abcdef

toupper : string → string

toupper s

This returns the string s with all lowercase letters changed to uppercase.

toupper "aBcDeF" ⇒ ABCDEF

trim : string → string

trim s ≡ replace ('^[ \t\f\r\n]+', replace ('[ \t\f\r\n]+$', s, ""), 
"")

Returns the string s with all leading and trailing spaces, tabs, form feeds, carriage returns, and new lines removed.

   trim " \tabc\n" ⇒ abc

uid : object → string

uid obj

This returns a unique ID for obj. No two objects in a given model can have the same ID. Two objects in two different models, however, can have the same ID, and a given object can have different IDs during different sessions. There is no structure to the ID strings, and the actual format could change in the future.

   uid anObject ⇒ 04240120
Note: This uid is NOT theIBM® Rational® Rhapsody® object uid and is valid within the context of Rational Rhapsody ReporterPLUS session.

unique : object collection → object collection

unique ocoll

This returns the collection ocoll with duplicate objects removed. Uniqueness is based on object identity. This doesn't preserve the relative ordering of the unique objects in ocoll.


Feedback