Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Everything You Ever Wanted to Know About Rexx (but were afraid to ask)
Howard Fosdick
(C) 2006 FCI Version 2.0
Who Am I?
Viewpoint / Purpose
All languages have their strengths & roles Not here to put down other languages Here to present Rexxs 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.
I. Why Scripting ?
Ka-Boom!
Free and Open Source Perl, Python, Rexx, Tcl/Tk, Bash, Korn, Ruby, others Scripting
General purpose
Free / open source Universal
Standardized (8 of 9 free Rexxes meet stds) Dynamic Sizing (variables & arrays) Memory management No variable declarations No data typing Integrated debugger
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
No
-- Optimal execution speed is required -- Systems -level programming (No BIOS interrupts, direct addressing, etc.)
Performance
Ratio of compiler to interpreter speed remains constant while processor speeds increase exponentially
200k
3M
1988 8 386
1993 66 486
FAST coding ! Reliable code Easy to code right out of memory Maintainable code
70%+ of IT does maintenance This determines your codes longevity Saves your company $$$
Power Conflict !
Simplicity
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
Rexx presents a radically different philosophy on how to achieve power than the Unix tradition languages (Perl, Bash, Korn, Awk, etc.)
Operators
Arithmetic Comparison Logical String
2 dozen Instructions
70 Built-in Functions
Other Features
Embedded--
Mainframes-- z/OS, z/VM, z/VSE (all versions) IBM iSeries-- i5/OS, OS/400 (all versions) Many others-- AmigaOS, AROS, MorphOS, OpenVMS, BeOS, OpenEdition, AtheOS/Syllable, SkyOS, QNX (QNX4/QNX6), OS/2, eCS, osFree, more
Many other good languages (Korn, C-shell, bash, Bourne, Lua, Mumps, etc)
Open source, general purpose scripting languages with critical mass -* Run everywhere (on all major OSs 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, etc)
NOTE-- The chart excludes non-open source (eg VB, VBScript) and non-general purpose (eg PHP) scripting languages
Reginald Windows
roo!
OOP extensions
NetRexx
Any Java Environment
Windows
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 . . .
Example Script # 1
/*******************************************************************/ /* Find Payments: */ /* Reads accounts lines one by one, and displays overdue */ /* payments (lines containing the phrase PAYMENT_OVERDUE). */ /*******************************************************************/ arg filein do while lines(filein) > 0 input_line = linein(filein) /* Read the input file name*/ /* Do while a line to read */ /* Read an input line */
if pos('PAYMENT_OVERDUE',input_line) > 0 then say 'Found it:' input_line end /* Write line if $ overdue */
No explicit file definition File is automatically OPENed and CLOSEd 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
filein
Do End
Do While Select
Call (case)
Subroutine or Function
Do Forever
Iterate
Leave (goto)
Signal
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. = '' area.CHICAGO = 312 area.HOMEWOOD = 708 area.EVANSTON = 847 do while town <> '' /* Initialize array entries to null */ /* Define a table of area codes */
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 end
*/ */ */
*/
/* The array of keywords to search for among the book descriptors keyword.1 = 'earth' keyword.3 = 'life' ; ; keyword.2 = 'computers' keyword.4 = 'environment'
*/
*/
say 'For weight of' weight 'retrieved titles are:' do j = 1 while title.j <> '' count = 0 do k = 1 while keyword.k <> ''
do l = 1 while title.j.l <> '' /* Compute its weight if keyword.k = title.j.l then count = count + 1 end
end
*/
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 I = 1 TO n DO UNTIL DO FOREVER DO n BY m WHILE condition FOR x
DO
IF
Key 4
Value 4
Key-value Pairs
b.1 b.1.1 b.2 b.2.1 b.2.2 b.2.3 b.3 b.4 Un-Balanced Tree
call display_linked_list list.99 = 'after a, before b' list.99.next = 2 list.1.next = 99 call display_linked_list exit
/* Display the linked list */ /* Add new item in list /* Point new item to next /* Point to the new item */ */ */
display_linked_list: /* Displays the linked list*/ sub = 0 do while list.sub.next <> TAIL say 'Element:' list.sub sub = list.sub.next end return
For a language that lacks data structures, Rexx sure has a lot of them!
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 90s
1996
TRL-1
TRL-2
SAA
ANSI
3.50
4.00
5.00
Language Level
Early 1980s
Mid 1990s
NetRexx
(for Java environments)
Rexx on Handhelds
+ Integrates with... + DOS Services + DOS Applications + Faster + Integrates with native services + Many DOS apps instantly available without any changes
Rexx Scripts
Rexx Interpreter
DOS Operating System DOS Emulator
Classic Rexx
Classes and Methods PLUS Inheritance & Derivation
Encapsulation
Abstraction Polymorphism
Object Rexx
New Instructions
More Functions
New Operators
NetRexx
A Rexx-like language Brings Rexx ease of use to Java environment NetRexx scripts use Java classes Script: Classes for use by Java Applets Applications Servlets Java Beans (EJBs) Client & server sides both
Object orientation
New instructions Changed and Extended with . . . Data typing (types) Indexed strings Special names Special methods and much more
Translate NetRexx source into a Java program Source script Eg: hello.nrx Java file Eg: hello.java Class file Eg: hello.class
NetRexx interprets and/or compiles. Can generate commented, formatted Java code. Runs under JVM or stand-alone.
Modularity
External Resources -- Extensions and Function Libraries -- Operating System Commands -- Commands to other environments -- External Programs -- API Interfaces to external features -- API into Rexx
abcabc
Parse Count = 2
Parsing Scans and analyzes a string, may split it into its constituent components Pattern Matching
Find def
abcdef
Parsing Operations
By Words Separate by words
By Pattern
Separate ,
using ,
commas
By Numeric Pattern
Columns:
Line-oriented
linein lineout
charin charout
lines
chars
+ More portable
QUEUE
Yes
Call Script X
Modularity
Comments Limit Nesting
Debugging Options
SAY Instruction
Interactive TRACE
+ Quick, informal + Great for simple problems + Requires changing code (adding SAY instructions)
+ Batch script trace + Can set trace level based on user input + Many trace settings available + Good for paperanalysis of a problem
+ Resolves challenging problems + Allows real-time code tests + Programmer-directed interaction resolves problems + Quick & easy, but powerful
VI. Conclusions
Conclusions
Resources
Find everything at www.RexxInfo.org -- download Rexx -- download tools -- tutorials, articles, how-tos -- reference materials
?
?
?
?
?
questions...
?
?
? ?