Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Object REXX
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Built-in functions and classes == As ooRexx aims to be compatible with classic Rexx, the traditional built-in functions are still available.<ref name=":9" /> Release 5.0.0 provides 82 built-in functions, including character manipulation, conversion and information functions, many of which call methods of the <code>String</code> class. In addition, the built-in [[Dynamic-link library|dynamic link library]] RexxUtil offers 29 cross-platform, 25 Windows-specific and four Unix-specific functions for manipulating system files, directories, classes and objects.<ref name=":2" /> In keeping with its object-oriented roots, ooRexx provides most of its functionality via built-in classes and methods. ooRexx 5.0.0 is delivered with a total of 57 built-in classes, which are divided into the class groups Fundamental, Stream, Collection and Utility.<ref name=":2" /> === Fundamental classes === Fundamental classes are the essential building blocks for all other classes. The <code>Object</code> class is the root of the [[class hierarchy]], so that its methods and attributes are available for all instantiated objects of each class. The <code>Class</code> class (a.k.a. meta class) is used to maintain the properties of a class (like its method objects) and gets used for creating instances (a.k.a. objects, values). Therefore, an [[Instance (computer science)|instance]] of this class (a.k.a. class object) is created for each <code>::CLASS</code> directive.<ref name=":2" /> The purpose of the <code>Method</code> class and <code>Routine</code> class is to create method or routine objects. The <code>String</code> class provides methods for handling strings, such as logical operations, concatenation, copying, joining, splitting, reversing, arithmetic, conversion, and others.<ref name=":9" /> A <code>Package</code> class instance contains all created routines, classes, and methods and manages external dependencies referenced by <code>::REQUIRES</code> directives. The <code>Message</code> class enables the asynchronous sending of messages, which enables the concurrent execution of methods.<ref name=":2" /><ref name=":9" /> === Stream classes === Stream classes facilitate communication with external objects such as files, queues, [[Serial port|serial interfaces]], devices, etc. The <code>Stream</code> class itself is a mixin class that can be inherited and is a subclass of the <code>InputOutputStream</code>, <code>InputStream,</code> and <code>OutputStream</code> classes.<ref name=":2" /> The <code>Stream</code> class provides methods for opening, reading, writing, and closing streams and flushing buffers, setting the file location, retrieving information, and other stream-related operations. While the <code>OPEN</code> method opens the stream, the <code>ARRAYIN</code> method can be used to read its content into an array object. The <code>CLOSE</code> method explicitly closes a stream before the stream object is reclaimed by the [[Garbage collection (computer science)|garbage collector]].<ref name=":2" /><ref name=":9" /><syntaxhighlight lang="oorexx" style="background-color: #ffffff; !important" line="1"> StreamObj = .stream~new("someFile.txt") /* create stream object */ StreamObj~open /* open the stream */ FileContent = StreamObj~ArrayIn /* read content */ StreamObj~close /* close the stream */ say FileContent /* outputs content */ </syntaxhighlight> === Collection classes === A collection is an object that contains multiple items with associated indexes that enable items to be retrieved using the <code>AT</code> or <code>[]</code> methods. There are MapCollection, SetCollection and OrderedCollection classes, all of which allow manipulation of a specific collection type.<ref name=":9" /> A MapCollection is a mixin class that defines the basic set of methods implemented by all collections that map from an index to a value. The <code>Directory</code>, <code>StringTable</code>, <code>IdentityTable</code>, <code>Properties</code>, <code>Table</code>, <code>Relation</code> and <code>Stem</code> classes inherit these methods.<ref name=":2" /> A Directory or a StringTable object is a collection of unique string indexes. In an IdentityTable object, each item is associated with a single index, and there can only be one item for each index. The Properties object provides specific methods for saving and loading properties into files. Unlike a Table object, which cannot contain duplicate indexes, a Relation object is a collection in which elements can have the same index, which can be of any object type. A Stem object is created automatically when a compound variable is used. As in classic Rexx, such a variable consists of a stem and a tail, separated by a dot (<code>.</code>). While the stem must begin with a letter, the tail can be any character. Using a single numeric tail creates the same effect as an [[Array (data type)|array]], while multiple numeric tails can be used to create a multidimensional array.<ref name=":2" /><ref name=":9" /><syntaxhighlight lang="oorexx" style="background-color: #ffffff; !important" line="1">fruits.1 = "Apple" /* assigning to stem variable */ fruits.4 = "Orange" /* assigning to stem variable */ say fruits.4 /* output: Orange */ say fruits.[1] /* output: Apple */</syntaxhighlight>SetCollections are special types of MapCollections where the index and the element are the same object. While the indexes in a <code>Set</code> object are unique, each index in a <code>Bag</code> object can appear more than once.<ref name=":2" /> An OrderedCollection is a mixin class that defines the basic methods for all collections that have an inherent index order, such as the <code>List</code>, <code>Queue</code>, <code>CircularQueue</code> and <code>Array</code> classes. A List object allows new items, for which a new index is created, to be added at any position in a collection. The associated index remains valid for that item regardless of other additions or removals. A Queue object allows items to be removed from the head and added to the tail or head of the queue. A CircularQueue object is a queue with a predefined size. Once the end of the circular queue is reached, new elements are inserted from the beginning to replace the previous items.<ref name=":2" /><ref name=":9" /> An Array is sequenced collection ordered by whole-number indexes. Like some other collection classes, the <code>Array</code> class provides the <code>MAKESTRING</code> method to encode its elements as a string object.<ref name=":2" /> <syntaxhighlight lang="oorexx" style="background-color: #ffffff; !important" line="1"> ArrayObj = .array~of("One", "Two", "Three") /* array with 3 items */ say ArrayObj~at(2) /* output: Two */ say ArrayObj~makeString(,"; ") /* output: One; Two; Three */ </syntaxhighlight> === Utility classes === Utility classes are a collection of 31 classes that provide implementations for common tasks. The <code>MutableBuffer</code> class enables greater efficiency in string operations such as concatenation, as no new object needs to be assigned. The <code>File</code> class provides methods for listing files in a directory or retrieving information about files and directories.<ref name=":2" /><syntaxhighlight lang="oorexx" style="background-color: #ffffff; !important" line="1"> FileObj = .File~new("~/someFolder/") /* create file object for folder */ FileArr = FileObj~ListFiles /* retrieve array of files */ do FilePath over FileArr /* iterate over the array items */ say FilePath /* output: FilePath item */ end </syntaxhighlight>The <code>DateTime</code> or <code>TimeSpan</code> classes support the retrieval and formatting of a date, time or timestamp in various formats and enable arithmetic operations between them. Several Comparator classes facilitate sorting for built-in classes such as File, DateTime and others. The class <code>Supplier</code> and its subclass <code>StreamSupplier</code> enable the enumeration of an items collection together with an indexes collection. The <code>Validate</code> class provides methods that can be used to check whether given arguments are of the correct class and type, or within a numerical range. A <code>VariableReference</code> instance maintains a reference, while a <code>WeakReference</code> instance creates a reference to another object that is not pinned.<ref name=":2" /> A [[regular expression]] is a pattern that can be used to match strings. To increase the readability of patterns in the code, the <code>RegularExpression</code> class allows the use of symbolic names encapsulated with colons (<code>:</code>) for common sets. For instance, matching a string containing only letters typically described as <code>[A-Za-z]</code> can be abbreviated using <code>[:alpha:]</code>.<ref name=":2" /> Other classes help to obtain information about the context of the currently executed code (<code>RexxContext</code>), the Rexx language or the executing platform (<code>RexxInfo</code>) and execution specifics (<code>StackFrame</code>) via environment symbols. The <code>Buffer</code> and <code>Pointer</code> classes are specifically designed to support writing methods and function in native code using the C/C++ APIs. <code>Alarm</code> and <code>Ticker</code> classes provide notification functions and <code>EventSempahore</code> and <code>MutexSempahore</code> classes implement synchronization mechanisms for multi-threading activities. The <code>Monitor</code> class enables messages to be forwarded to various target objects and the <code>RexxQueue</code> class provides object-like access to external Rexx data queues.<ref name=":2" />
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)