Free Rexx Everything You Ever Wanted to Know






























































- Slides: 62
Free Rexx ! Everything You Ever Wanted to Know About Rexx (but were afraid to ask) Howard Fosdick (C) 2006 FCI Version 2. 0
Who Am I? • Presentation by Howard Fosdick, author of Rexx Programmer’s Reference • Find the book at www. Amazon. com/rexx • This presentation is published under the Open Publication License (OPL).
Viewpoint / Purpose • All languages have their strengths & roles • Not here to “put down” other languages • Here to present Rexx’s strengths and discuss where it fits in your toolbox Goals: (1) Know where Rexx fits (2) Teach you to script it in < 2 hours !
Outline 1. 2. 3. 4. Why Scripting ? Why Rexx ? Rexx Tutorial Further Info
I. Why Scripting ?
2 Big Software Trends Converge Ka-Boom! Free and Open Source Java, C/C++, COBOL Scripting Perl, Python, Rexx, Tcl/Tk, Bash, Korn, Ruby, others Visual Basic, VBScript, WSH
What’s a Scripting Language ? Rexx: • Interpreted • High-level • Glue language • General purpose • Free / open source • Universal • • Portable code Transferable skills • Standardized (8 of 9 free Rexxes meet stds) • Dynamic • Sizing (variables & arrays) • Memory management • No “variable declarations” • No “data typing” • Integrated debugger
Scripting Vs. Traditional Languages Scripting ----- High level Interpretive More productive Varying degrees of automatic variable management -- Shifts burden to the machine -- “Glue” languages -- Acceptable execution speed Rexx, Perl, Python, Tcl/Tk, Ruby, others Traditional ----- Lower level Compiled More detail-oriented Manual variable management Pre-declared variables More programmer effort “Coding” languages Optimize execution speed C/C++, COBOL, Java, Pascal, others
When to Use Rexx Yes -- Productivity -- Reliability -- Quick development -- Glue language -- Prototyping -- Systems administration -- OS extensions -- Portable apps -- Mainframe migrations -- Embedded programming -- Handhelds -- Text processing -- Interactive development / debugging No -- Optimal execution speed is required -- Systems -level programming (No BIOS interrupts, direct addressing, etc. )
Performance 3 M Ratio of compiler to interpreter speed remains constant while processor speeds increase exponentially 200 k 10 k 70 Year-- 1981 Mhz-- 4. 77 CPU-- 8088 4 k 1988 8 386 1993 66 486 1998 266 PII 2005 3 ghz PIV
II. Why Rexx ?
Why Rexx Vs Other Scripting Languages ? “Easy but Powerful” Ease of use benefits experienced developers. . . • FAST coding ! • Reliable code • Easy to code right out of memory • Maintainable code • • • 70%+ of IT does maintenance This determines your code’s longevity Saves your company $$$
Why Rexx Vs Other Scripting Languages ? Power Simplicity Conflict ! Rexx uses specific technologies to tie them together
Power Through Simplicity by… • • Small instruction set, w/ power in the functions Extensible Call external functions just like internal Glue language (uses OS commands, interfaces, DLLs, shared libraries, services, objects, etc. ) • Minimal syntax • Minimal special characters, variables, etc. • Automated memory management • Automated variable management • No data definitions • No data typing • Dynamic array sizes • Dynamic string or variable lengths
Power Through Simplicity… Rexx presents a radically different philosophy on how to achieve power than the “Unix tradition” languages (Perl, Bash, Korn, Awk, etc. ) Rexx presents a unique scripting paradigm
The Language Structure Makes Rexx Easy Operators Arithmetic Comparison Logical String 2 dozen Instructions 70 Built-in Functions Learn from the inside out Other Features OS commands, external functions, DLLs, APIs, widgets, etc.
Rexx Runs Everywhere… Linux-Unix-BSD-Windows-Mac OS-DOS all versions all versions (32 - and 16 - bit), IBM PC-DOS 2000 and 7 Handhelds-- Windows CE / Mobile / PPC / etc, Palm OS, Symbian/EPOC 32, EPOC, DOS emulation Embedded-- Embedded Linux, DOS, Windows variants Mainframes-- z/OS, z/VM, z/VSE (all versions) IBM i. Series-- i 5/OS, OS/400 (all versions) Many others-- Amiga. OS, AROS, Morph. OS, Open. VMS, Be. OS, Open. Edition, Athe. OS/Syllable, Sky. OS, QNX (QNX 4/QNX 6), OS/2, e. CS, os. Free, more… Rexx predominates on systems in red
Rexx Has Critical Mass. . . Perl Python Critical mass Rexx, Tcl/Tk, Ruby Many other good languages (Korn, C-shell, bash, Bourne, Lua, Mumps, etc) Do not have critical mass Open source, general purpose scripting languages with critical mass -* Run everywhere (on all major OS’s and platforms) * Have strong standards * Enjoy wide use and offer good support * Internationally * In many spoken languages * Offer thousands of free tools and scripts * Interface to everything (databases, web programming, GUIs, etc) NOTE-- The chart excludes non-open source (eg VB, VBScript) and non-general purpose (eg PHP) scripting languages
The Free Rexx Interpreters Regina Rexx/imc All major operating systems Reginald r 4 Windows roo! Windows Unix, Linux, BSD OOP extensions Open Object Rexx Linux, Windows, Solaris, AIX BRexx Windows, DOS (32/16 bit), Windows CE, Linux, Unix, Mac OS, Amiga. OS, others Rexx for Palm OS Net. Rexx Any Java Environment
Rexx Free Tools and Interfaces • Over 2000 free tools & scripts for Rexx. Examples: • • • SQL database access GUIs XML Web programming Math libraries Regular Expressions Code managers Communications functions OS interface libraries Graphics Speech, MIDI, sound. . . you name it. . .
III. Let’s Code !
Example Script # 1… /**********************************/ /* Find Payments: */ /* Reads accounts lines one by one, and displays overdue */ /* payments (lines containing the phrase PAYMENT_OVERDUE). */ /**********************************/ arg filein /* Read the input file name*/ do while lines(filein) > 0 /* Do while a line to read */ input_line = linein(filein) /* Read an input line */ if pos('PAYMENT_OVERDUE', input_line) > 0 then say 'Found it: ' input_line end /* Write line if $ overdue */
Simplicity in this script… • • • Minimal syntax Minimal special characters and variables Free format Use spaces & blank lines however desired Case-insensitive (capitalize however you want) • No explicit file definition • File is automatically OPEN’ed and CLOSE’d • Automatic “declaration” of variables (see FILEIN and INPUT_LINE) • No “data typing” • All variables are strings • Numbers are strings that look like numbers • Decimal arithmetic (portable, consistent results) • Automatic conversions where sensible
What is “Power” ? Is it the number of Lines of Code (LOC) ? • Can reduce LOC by nesting functions • But why write a complex “fortune-cookie” script ? Power is not solving the problem in the fewest LOC! Power is a deft script that solves the problem in a reliable, readable, maintainable manner
Example Script # 2… arg filein fgrep PAYMENT_OVERDUE filein This script does the same thing as Example #1
The Power of Glue Languages • Rexx evaluates a statement, sends anything that is not Rexx to the “external environment” (by default this is the OS) • Full power of a string-manipulation language to direct external interfaces • Inspect return code, command output, messages, and respond • Rexx is a glue language
Structured Control Instructions Do End If Do While If then else Select Call (case) Subroutine or Function
Un-Structured Control Instructions Do Until Do Forever Iterate Leave Signal (goto)
Rexx Functions… • 70 Built-in Functions: • • String manipulation (character, bit, hex) Word manipulation I/O Numeric Environmental Conversion Other • 2 statements access external function library • Those functions are then coded just like built-ins
Example Script # 3… /**********************************/ /* Code Lookup: */ /* Looks up the area code for the town the user enters. */ /**********************************/ area. = '' /* Initialize array entries to null */ area. CHICAGO = 312 area. HOMEWOOD = 708 area. EVANSTON = 847 /* Define a table of area codes do while town <> '' /* Loop until user enters null line */ say 'For which town do you want the area code? ' pull town if town <> '' then do if area. town = '' then say 'Town' town 'is not in my database' else say 'The area code for' town 'is' area. town end */
Simplicity in this script… • Array recognized by the period (area. ) • Do not have to declare arrays or predefine their size • Sets all possible elements to null string (area. = ‘’) • Subscript array by any arbitrary string (content-addressable memory or associative memory) • Arrays can be: • Dense or sparse • Contain homogenous or heterogeneous elements • Represent records or C structs • Expand to size of memory • Automatic capitalization (pull & array element names) • Can always override Rexx’s automation
Example Script # 4… (part I) /* /* /* Find Books: This program illustrates how arrays may be of any dimension in retrieving book titles based on their keyword weightings. keyword. = '' title. = '' /* Initialize both arrays to all null strings /* The array of keywords to search for among the book descriptors keyword. 1 = 'earth' keyword. 3 = 'life' ; ; */ */ */ keyword. 2 = 'computers' keyword. 4 = 'environment' /* The array of book titles, each having several descriptors title. 1 = 'Saving Planet Earth' title. 1. 1 = 'earth' title. 1. 2 = 'environment' title. 1. 3 = 'life' title. 2 = 'Computer Lifeforms' title. 2. 1 = 'life' title. 2. 2 = 'computers' title. 2. 3 = 'intelligence' title. 3 = 'Algorithmic Insanity' title. 3. 1 = 'computers' title. 3. 2 = 'algorithms' title. 3. 3 = 'programming' */
Example Script # 4… (part II) arg weight /* Get number keyword matches required for retrieval */ say 'For weight of' weight 'retrieved titles are: ' do j = 1 while title. j <> '' count = 0 do k = 1 /* Output header */ /* Look at each book while keyword. k <> '' */ /* Inspect its keywords */ do l = 1 while title. j. l <> '' /* Compute its weight if keyword. k = title. j. l then count = count + 1 end */ end if count >= weight then say title. j end /* Display titles matching the criteria */
Discussion • Array keyword. is a lookup table or list • key/value pairs like Perl or Berkeley DB • Array title. is a tree • Trees can be balanced or not DO IF DO I = 1 TO n DO UNTIL … DO FOREVER DO n BY m IF condition THEN DO. . . END ELSE DO. . . END WHILE condition FOR x Enclose multiple statements within a DO END pair
Create Any Data Structure With Rexx Arrays : Element 1 Element 2 Element 3 A Simple List or Look-up Table b. 1. 1 b. 1. 2 b. 2. 1 b. 2. 2 b. 3. 1 b. 3. 2 Balanced Tree Key 1 Value 1 Key 2 Value 2 Key 3 Value 3 Key 4 Value 4 Key-value Pairs b. 1. 1 b. 2. 2 b. 2. 3 b. 4 Un-Balanced Tree b. 1. 1. 2 b. 2. 1 b. 2. 2 b. 2. 3 b 3. 1 b. 3. 1. 1. 1 A Multi-level Tree (unbalanced) Also: linked list, doubly linked list, stack, queue, dequeue, etc. . .
Example-- Creating a Linked List list. 0 list. 1 list. 2 list. 3 = = HEAD 'a' 'b' TAIL ; ; list. 0. next list. 1. next list. 2. next list. 3. next = = 1 2 3 TAIL /* Define linked list. /* You could also /* create it /* dynamically. */ */ call display_linked_list /* Display the linked list */ list. 99 = 'after a, before b' list. 99. next = 2 list. 1. next = 99 /* Add new item in list /* Point new item to next /* Point to the new item call display_linked_list exit /* Display the linked list */ */ display_linked_list: /* Displays the linked list*/ sub = 0 do while list. sub. next <> TAIL say 'Element: ' list. sub = list. sub. next end return
Why Rexx Vs Other Scripting Languages ? For a language that “lacks data structures, ” Rexx sure has a lot of them! Power thru Simplicity!
IV. More about Rexx
Rexx Standards Extensions TRL-2 ANSI • • 8 of 9 free Rexx interpreters adhere to TRL-2 ANSI adds little beyond TRL-2 Most Rexxes offer extensions Extensions offer OS-specific stuff and other niceties
Rexx Standards 1985 1990 Early 90 s TRL-1 TRL-2 SAA 3. 50 4. 00 1996 ANSI 5. 00 Language Level
The Evolution of Rexx Object-oriented Rexx Early 1980 s Mid 1990 s Standard or “Classic” Rexx Net. Rexx (for Java environments)
Rexx on Handhelds Native Windows CE Palm OS Symbian / EPOC 32 DOS Emulation Interpreter: BRexx for Palm OS Regina Interpreter: Pocket. DOS XTM others BRexx + Integrates with. . . + DOS Services + DOS Applications + Faster + Integrates with native services + Many DOS apps instantly available without any changes
How DOS Emulation Works Rexx Scripts Rexx Interpreter DOS Operating System DOS Emulator Native operating system PC Hardware Each layer runs on top of the one below it
Object-Oriented Rexx Means… Classic Rexx PLUS Classes and Methods Inheritance & Derivation Encapsulation Abstraction Polymorphism Huge Class Library
Object Rexx Adds to Classic Rexx. . . Complete Object Orientation Classes and Methods Object Rexx New Instructions More Functions New Operators Built-in Objects, Special Variables, many other features And Much More
Net. Rexx • A “Rexx-like” language • Brings Rexx ease of use to Java environment • Net. Rexx scripts use Java classes • Script: • Classes for use by Java • Applets • Applications • Servlets • Java Beans (EJBs) • Client & server sides both
Net. Rexx Goes Beyond Classic Rexx… Classic Rexx Java environment integration Object orientation Changed and Extended with. . . New instructions Data typing (“types”) Indexed strings Special names Special methods … and much more …
Developing and Running Net. Rexx Scripts To translate, compile and run in one step enter: nrc -run hello Translate Net. Rexx source into a Java program Source script Eg: hello. nrx Java file Eg: hello. java Class file Eg: hello. class Compile Java into bytecode Run Net. Rexx interprets and/or compiles. Can generate commented, formatted Java code. Runs under JVM or stand-alone.
V. More Rexx Features
Modularity Internal Routines -- Built-in Functions -- Functions you develop -- Subroutines How Rexx Supports Modularity External Resources -- Extensions and Function Libraries -- Operating System Commands -- Commands to other environments -- External Programs -- API Interfaces to external features -- API into Rexx
String Processing Operations abc + abcabc Concatenation Joins two or more strings abcabc Bifurcation abc abcabc Splits a string Parse Count = 2 abcdef Scans and analyzes a string, may split it into its constituent components Pattern Matching Find “def” Identifies patterns in strings
Parsing Operations By Words Separate By Pattern Separate , By Numeric Pattern Columns: by using , abc abc 1 5 9 words commas
The Two I/O Modes Line-oriented Character-oriented Process one line at a time Process one character at a time linein charin lineout charout lines chars + More portable + Reads “special” characters
The Stack is both a Stack and a Queue PUSH PULL, PARSE PULL QUEUE Rexx’s Stack is a generalized communications mechanism
Rexx Supports Recursion How Recursion Works Script X End Test Fufilled ? No Call Script X Yes
Tip – Steps to Good Programming Style Ect ! Error checking Structured Code Modularity Comments Limit Nesting Spacing & indentation Good variable names Capitalization
Debugging Options SAY Instruction TRACE Instruction in batch mode + Quick, informal + Great for simple problems + Requires changing code (adding SAY instructions) Interactive TRACE + Resolves challenging problems + Allows real-time code tests + Programmer-directed interaction resolves problems + Quick & easy, but powerful + Batch script trace + Can set trace level based on user input + Many trace settings available + Good for “paperanalysis” of a problem
Condition / Exception Trapping signal on condition name label_name …code of the main routine. . . label_name: …code of the error handling routine. . . Conditions: error, failure, halt, novalue, notready, syntax, lostdigits
VI. Conclusions
Conclusions • Free & open source languages have taken over • Scripting is the “quiet revolution” • Rexx offers “Power through Simplicity” • Useful addition to your toolbox
Resources Find everything at www. Rexx. Info. org -- download Rexx -- download tools -- tutorials, articles, how-to’s -- reference materials Rexx Programmer’s Reference at Amazon www. amazon. com/rexx
? ? ? questions. . . ? ?