Object REXX
Object REXX is a high-level, general-purpose, interpreted, object-oriented (class-based) programming language. Today it is generally referred to as ooRexx (short for Open Object Rexx), which is the maintained and direct open-source software successor to Object REXX. It is a follow-on and a significant extension of the Rexx programming language (called here classic Rexx), retaining all the features and syntax while adding full object-oriented programming (OOP) abilities and other new enhancements. Following its classic Rexx influence, ooRexx is designed to be easy to learn, use, and maintain. It is essentially compliant with the "Information Technology – Programming Language REXX" American National Standards Institute (ANSI) X3.274-1996 standard and therefore ensures cross-platform interoperability with other compliant Rexx implementations. Therefore, classic Rexx programs typically run under ooRexx without any changes. There is also Rexx Object Oriented (roo!), which was originally...
Object REXX is a high-level, general-purpose, interpreted, object-oriented (class-based) programming language. Today it is generally referred to as ooRexx (short for Open Object Rexx), which is the maintained and direct open-source software successor to Object REXX. It is a follow-on and a significant extension of the Rexx programming language (called here classic Rexx), retaining all the features and syntax while adding full object-oriented programming (OOP) abilities and other new enhancements. Following its classic Rexx influence, ooRexx is designed to be easy to learn, use, and maintain. It is essentially compliant with the "Information Technology – Programming Language REXX" American National Standards Institute (ANSI) X3.274-1996 standard and therefore ensures cross-platform interoperability with other compliant Rexx implementations. Therefore, classic Rexx programs typically run under ooRexx without any changes. There is also Rexx Object Oriented (roo!), which was originally developed by Kilowatt Software and is an unmaintained object-oriented implementation of classic Rexx. As in classic Rexx, there are assignment instructions, keyword instructions and command instructions. In line with the desire to keep the language small, ooRexx has only thirty keyword instructions. Unlike many other languages, no keywords are reserved, so keyword instructions such as DO , SAY , END and IF for example can be used as variable names during an assignment. This avoids having to memorize a long list of reserved words. An assignment is used to set or change the value of a variable. The equal sign ( = ) is used to create an assignment instruction which can be used in combination with eleven operators for extended assignment sequences such as += , -= , *= and others. Keyword instructions such as ARG , PARSE , PULL or USE have the same effect as assignments. In cases where an instruction is neither an assignment nor a keyword instruction, it must be a valid expression, e.g., a symbol, a string literal, which is considered a command instruction, whose value the interpreter passes to the current command environment, e.g., editor, operating system, for execution; the interpreter sets a variable RC for the return code. In addition, the ADDRESS instruction allows commands to be redirected to specific command environments such as Bourne Shell, Bash, Z-Shell, Command Prompt and others, some editors including ISPF, TSO EDIT, XEDIT and its adaptations, as well as intercepting errors. a = "hello world" /* assignment instruction */ do i = 1 to 2 /* keyword instruction "DO" */ say "round #" i":" a /* keyword instruction "SAY" */ end /* keyword instruction "END" */ "echo Hello World" /* command to operating system */ say "RC:" rc /* command's numeric return code */ In addition to the three instruction types of classic Rexx, ooRexx adds directive instructions which need to be placed at the end of the program. After loading and the syntax check, the interpreter executes all defined directives to set up the execution environment for the program before further instructions are executed. Directives can be used to define routines, classes, methods, attributes or execution options like the number of digits to use in arithmetics. To make directive instructions readily recognizable, they are introduced with two consecutive colons ( :: ). To facilitate the reusability of code, the ::REQUIRES directive allows the integration of another Rexx program (also known as a package) or an external (native) library. This directive causes the interpreter to make every routine and class that specifies the PUBLIC option of the denoted Rexx program (package) to become directly accessible. External packages usually use the file extension .cls , for example ::requires "csvstream.cls" or ::requires "json.cls" . Some external packages and libraries are delivered with the ooRexx interpreter. say "Hello World!" /* output: Hello World! */ say " This" 'is' - /* trailing dash for continuation */ "REXX" || "!" /* output: This is REXX! */ As classic Rexx, ooRexx is a case-insensitive programming language. Accordingly, the ooRexx interpreter capitalizes all characters outside quotation marks (single or double) and ignores case for instructions, variable names and all other aspects of the language. Only sequences within quotation marks are treated as literal strings and are not changed during processing. Because the cases do not need to be differentiated, fewer additional details need to be learned and frustrating syntax errors are avoided. a = "This is" rexx! Say A /* output: This is REXX! */ SAY a /* output: This is REXX! */ In ooRexx, a string variable is a reference to a string object and does not need to be declared, which reduces the effort for programmers compared to strictly typed languages. A string object can be of any length and contain any characters, including numerical values. It is therefore possible to change numerical values with string manipulations and methods of the String class. In addition, a string variable can contain any type of expression, including executable instructions, which can be evaluated or executed with the INTERPRET keyword instruction. a = 2 /* string with numerical value */ a = a || '0' /* resulting string: 20 */ str = "do i = 1 to "a"; say i; end" /* string contains loop instruction */ interpret str /* interpret string: counts to 20 */ The default behavior of most methods can be changed by specifying an option, which can be either spelled out or abbreviated and is not case-sensitive. When reading code, this enables a literal understanding and reduces the learning effort for beginners, as there is no need to learn the meaning of abbreviations. For example, the method with the name strip removes leading and trailing blanks by default. This behavior can be changed, for example, by specifying "leading" or "l" as an option. While functions are nested in classic Rexx, messages can be chained in ooRexx, which improves the readability of a statement. a = " I am ooRexx!" say a /* output: I am ooRexx! */ say a~Strip("Leading") /* output: I am ooRexx! */ say a~strip("l")~reverse /* output: !xxeRoo ma I */ ooRexx is designed to retain all the features of classic Rexx and essentially complies with the ANSI standard for the Rexx language (X3.274-1996, "Programming Language REXX"). In contrast to an optional specification in the ANSI standard, ooRexx does not allow characters such as @ , # , $ and ¢ in symbols. While in classic Rexx the expression b. = a. results in b. being assigned the default value of a. , the interpreter makes b. an alias for a. . In addition, ooRexx allows -- as a comment mark and - as a line continuum, which are not specified in the standard. Classic Rexx scripts typically run without changes under ooRexx, making it easy to migrate to OOP features at the desired rate while preserving the time invested in the original code. There are incompatibilities with some platform-specific implementations such as Rexx for z/VM (e.g. PARSE EXTERNAL is not supported by ooRexx). While classic Rexx allows empty assignments such as x = ; , quotation marks x = ""; are necessary in ooRexx. The default behavior of built-in functions can be changed by adding a label with the same name as the function to be overridden (e.g. date ) at the end of the program scope or by adding a ::routine directive. The code can either calculate results itself or modify the results of the original built-in function. say Date() /* output, e.g.: 16 JUN 2025 */ exit Date: return newDate() /* label pointing to "newDate" routine */ Routine newDate newDate = date()~upper /* use of date() BIF, but with capital letters */ return newDate Since ooRexx 5.0.0 namespaces have been added that allow the subclassing of built-in classes. This makes it possible to extend built-in classes, e.g. by adding a method such as ArrayInClose to the stream class, which opens the stream, reads the content and closes the stream instead of doing this in the program scope. Say .stream~new("someFile.txt")~ArrayInClose Class stream subclass rexx:stream /* create a subclass of stream */ ::Method ArrayInClose /* add new method to stream class */ self~open /* open the stream */ FileContent = self~ArrayIn /* read content */ self~close /* close the stream */ return FileContent /* return content */ The definition of an UNKNOWN method enables objects to receive unspecified messages. Two arguments are passed, firstly the name of the unspecified method and secondly an array of arguments from the original message. This is a basic mechanism of the Java Bridge, which enables among other things the use of all available Java methods. PackageObj = .Package~new PackageObj~SomeMethod("First", "Second", "Third") Class Package ::Method Init ::Method Unknown Use arg MethodName, ArgArr say "Method was:" MethodName /* output: Method was: SOMEMETHOD */ say ArgArr /* output: First, Second, Third */ The PARSE keyword instruction makes it possible to quickly and flexibly parse a string and assign parts of it to variables in a single step. Subsequent instruction is used to specify the source of the string, for example ARG for arguments that are listed when the program or function is called, VAR for variables, PULL for data queues or standard input (typically the keyboard), VALUE for any expression. When using VALUE , the WITH keyword is required to specify the end of an expression, followed by a parsing pattern. This pattern can be a list of variables, a position number or literal delimiters; it is possible to use these patterns in combination. Optionally, the upper and lower case of the string can be converted before parsing. str = "Person: Rick McGuire" /* parse string using the literal ":" and blanks between words into variables a ("Person"), b ("Rick"), and c ("McGuire") */ parse var str a ":" b c /* parse by literal and blank */ say b c /* output: Rick McGuire */ ooRexx provides a new way to define procedures and functions that are not specific to a particular class by using the ::ROUTINE directive; unlike the older PROCEDURE , code defined with ::ROUTINE has an implicit RETURN at the end. The CALL instruction can be used to invoke a routine as a procedure. In addition, routines that return values via the RETURN keyword instructions can be called using function calls by specifying the name of the routine followed by parentheses. The content within the parentheses is passed as arguments to the routine. While the PARSE ARG instruction can be used to parse received string arguments and assign them to variables, the newer USE ARG must be used for objects of other types. In addition, the STRICT option can be used to limit the number of arguments that must match the number of specified names. call DoSomething /* "CALL" keyword instruction */ table = .stem~new /* Stem object for indsum */ table[1] = 2; table[2] = 4 say indsum{table,1.2) /* function call requiring use arg */ say dirsum(2,4) /* either parse arge or use arg okay */ Routine DoSomething /* "ROUTINE" directive (procedure) */ say "I did something!" /* output: I did something! */ /* Implicit return because next */ /* statement is a directive. */ Routine dirsum /* "ROUTINE" directive (function) */ parse arg first, second /* Valid because both are strings. */ return first+second Routine indsum /* "ROUTINE" directive (function) */ use strict arg table, first, second /* can't use parse arg with stem arg */ Sum = table{first} + table[second] /* do calculation */ return Sum /* "RETURN" result */ The ::CLASS directive followed by a class name causes the interpreter to define a new class. After the class name, options such as METACLASS , SUBCLASS , MIXINCLASS , ABSTRACT and INHERIT can be set in order to use OOP features. The ::METHOD directive can be used to define a new class method that is associated with the last ::CLASS directive. The ::ATTRIBUTE directive is used to define an accessor method that can retrieve or assign an object variable. Using the EXPOSE instruction, an object variable can be directly exposed to a method. d = .dog~new("Bella") /* create and assign a dog */ d~bark /* send bark message */ say d~name /* output: Bella */ class dog /* class directive */ attribute name /* attribute directive */ method init /* object initiation method */ Expose name /* exposes name of dog */ use arg name /* assigns "Bella" to name */ method bark /* method directive */ Expose name say Name "goes woof!" /* output: Bella goes woof! */ The built-in CONDITION function can be used to retrieve information such as the name of the current intercepted condition and the resulting instruction process, the status of the intercepted condition, a descriptive string and additional object information. Signal on Syntax /* switch on SYNTAX trap */ Say 1 + "AString" /* an impossible calculation */ Exit SYNTAX: ConditionObject = Condition(Object) /* get additional information */ say "Error code is" ConditionObject~Code /* output: Error code is 41.1 */ say ConditionObject~ErrorText /* output: Bad arithmetic conversion. */ Similarly, the CALL keyword instruction can be used not only to invoke a routine, but also to control the trapping of certain conditions when ON or OFF is specified along with a specific condition trap (e.g. CALL ON HALT and CALL OFF HALT ). These instructions do not flush the control stack, and normal execution resumes when the condition handler returns. The amount of additional information provided can be specified by using either the "Thread" , "Standard" , "Full" or "Profiling" option. As an example, the "Full" option shows interpreted instance, thread, invocation and attribute pool IDs as well as the current guard state, the lock count, guard lock reserved indicator and waiting state. trace off /* do not trace prolog */ .TraceObject~option = "Full" /* set option to "Full" */ .TraceObject~collector = .array~new o = .Test~new /* create an instance */ say "starting worker asynchronously ..." o~start("do") /* dispatched on a new thread */ say "about to wait for worker to end ..." o~wait /* synchronize with worker */ say "waiting is over" class Test method init /* constructor */ expose lock /* access attribute */ lock = .true /* set default */ method wait unguarded expose lock /* access attribute */ guard on when lock = .false method do /* do some work */ expose lock /* access attribute */ t = random(1,999)/1000 say "do: working for" t "secs" call sysSleep t say "do: ending work" lock = .false /* release lock */ options trace results The ooRexx debugger, which is also included in the "net-oo-rexx" bundle, is based on Trace and offers a graphical user interface (GUI) that uses the Java bridge to facilitate debugging on all platforms. The Stream 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 OPEN method opens the stream, the ARRAYIN method can be used to read its content into an array object. The CLOSE method explicitly closes a stream before the stream object is reclaimed by the garbage collector. 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 */ 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 ( . ). 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, while multiple numeric tails can be used to create a multidimensional array. fruits.1 = "Apple" /* assigning to stem variable */ fruits.4 = "Orange" /* assigning to stem variable */ say fruits.4 /* output: Orange */ say fruits.[1] /* output: Apple */ SetCollections are special types of MapCollections where the index and the element are the same object. While the indexes in a Set object are unique, each index in a Bag object can appear more than once. An OrderedCollection is a mixin class that defines the basic methods for all collections that have an inherent index order, such as the List , Queue , CircularQueue and Array 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. An Array is sequenced collection ordered by whole-number indexes. Like some other collection classes, the Array class provides the MAKESTRING method to encode its elements as a string object. ArrayObj = .array~of("One", "Two", "Three") /* array with 3 items */ say ArrayObj~at(2) /* output: Two */ say ArrayObj~makeString(,"; ") /* output: One; Two; Three */ Utility classes are a collection of 31 classes that provide implementations for common tasks. The MutableBuffer class enables greater efficiency in string operations such as concatenation, as no new object needs to be assigned. The File class provides methods for listing files in a directory or retrieving information about files and directories. 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 The DateTime or TimeSpan 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 Supplier and its subclass StreamSupplier enable the enumeration of an items collection together with an indexes collection. The Validate 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 VariableReference instance maintains a reference, while a WeakReference instance creates a reference to another object that is not pinned. A regular expression is a pattern that can be used to match strings. To increase the readability of patterns in the code, the RegularExpression class allows the use of symbolic names encapsulated with colons ( : ) for common sets. For instance, matching a string containing only letters typically described as [A-Za-z] can be abbreviated using [:alpha:] . Other classes help to obtain information about the context of the currently executed code ( RexxContext ), the Rexx language or the executing platform ( RexxInfo ) and execution specifics ( StackFrame ) via environment symbols. The Buffer and Pointer classes are specifically designed to support writing methods and function in native code using the C/C++ APIs. Alarm and Ticker classes provide notification functions and EventSempahore and MutexSempahore classes implement synchronization mechanisms for multi-threading activities. The Monitor class enables messages to be forwarded to various target objects and the RexxQueue class provides object-like access to external Rexx data queues. The Rexx extension library offers classes for reading and writing comma-separated values (CSV) files, as well as for creating and processing JavaScript Object Notation (JSON) data. A library called "hostemenu" is also included, which partially emulates a TSO/CMS environment. The RxSock native library enables to incorporate TCP/IP protocols, while the RxFtp native library specifically provides access to the file transfer protocol (FTP). The RxMath native library offers advanced mathematical functions such as square root calculation, exponential function, logarithm, sine, cosine, tangent, arc sine and power calculation. Say rxcalcsin(1) /* output: 0.0174524064 */ requires 'rxmath' LIBRARY /* load a native library */ For Windows, ooRexx includes the ooDialog framework allowing to produce Windows dialogs and therefore graphical user interfaces. The interpreter is delivered with several example programs and function packages that demonstrate the use of this framework. For POSIX-compatible operating systems, the orxnCurses class library enables the writing of text-based user interfaces using the ncurses programming library. The RxUnixSys library provides functions on most Unix systems for interacting with processes and threads, users and user groups, files and file systems and other. Many of these external packages and libraries are also compatible with other Rexx implementations. Using the C++ APIs, BSF4ooRexx was developed as a bidirectional Java bridge based on the Bean Scripting Framework. This bridge enables ooRexx to communicate with Java objects and Java to interact with Rexx applications. The bridge is realized by requiring the ooRexx package BSF.CLS , which defines public routines, classes and the environment symbol .BSF4REXX . Examples are provided for the use of Java classes in connection with AWT, Swing, JavaFX, JDBC, Java 2D and some others. /* create Java object */ frame=.bsf~new("javax.swing.JFrame", "Hello, my beloved world - from ooRexx!") frame~setSize(410,20) /* set width and height */ frame~visible=.true /* make JFrame visible */ call SysSleep 10 /* sleep for ten seconds */ requires "BSF.CLS" /* get Java support */ Based on BSF4ooRexx, interaction with Universal Network Objects (UNO), as used in OpenOffice and LibreOffice, is supported via the UNO.CLS package. The CLR.CLS package together with Jini4Net enables the use of the .NET framework. Communication with processes via the D-Bus middleware under Linux is possible using the DBUS.CLS package. The JDOR.CLS package provides a command handler that leverages the Java2D classes (based on AWT) for graphics rendering. Based on the JDOR command handler, the experimental JDORFX.CLS package enables the rendering of 3D graphics using JavaFX 3D classes. The Windows extension includes the Windows Script Host (WSH) Scripting Engine that can be used to perform general automation tasks. It also includes Object Linking and Embedding/ActiveX (OLE) support allowing to interact with Windows programs via the OLEObject . OLE Automation is an inter-process communication mechanism developed by Microsoft that is based on a subset of the Component Object Model (COM). This mechanism enables, among other things, the invocation of program functions, the querying and setting of attributes and the interception of component events. The ooRexx interpreter comes with examples that demonstrate OLE interaction with Access, Word, Excel, OpenOffice/LibreOffice, ActiveDirectory, WMI and other programs. Furthermore, a utility program for searching available OLE objects is included. exc = .OLEObject~new("Excel.Application") /* create object for Excel */ exc~visible = .true /* make Excel visible */ Worksheet = exc~Workbooks~Add~Worksheets[1] /* add worksheet */ Worksheet~cells(1,1)~Value = "First Cell" /* insert string into cell */ In addition to OLE support, the Windows extension enables interaction with the Windows program manager, the system event log, the clipboard and the registry as well as to query, edit and interact with windows, menus or sub-menus. ==External links== Rexx Language Association Open Object Rexx 5.1.0 documentation Open Object Rexx on SourceForge Open Object Rexx Website Open Object Rexx on Rosetta Code BSF4ooRexx on SourceForge ooRexx Debugger on SourceForge Net-oo-Rexx
Cite this
"Object REXX". 1790303176. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1376608617