Formation Future NetRexx

Formation Future NetRexx, tutoriel & guide de travaux pratiques en pdf.

Peculiarities of NetRexx

 The Rexx Data type – implicit in other implementations, but not named due to untyped usage
 PARSE
 TRACE
 Arbitrary numeric precision & decimal arithmetic
 Concatenation by abuttal
 No reserved words
 Case insensitive
 Automates type selection and declaration
 Autogeneration of JavaBeans properties (with properties indirect)
 Philosophy: a language should be easy for users, not interpreter writers
 ‘No reserved words’ ensures that old programs are never broken by language evolution

The Rexx Data Type

 This is where statically typechecked meets type-less
 A Rexx instance can be a number or a (Unicode) string of characters
 3+4 is the same as “3” + “4”
 We can perform (arbitrary precision) arithmetic on it when it is a number
 The Rexx type keeps two representations under the covers (if needed)
 The Rexx way to handle decimal arithmetic ended up in Java and in IEEE 754r, implementation of BigDecimal actually written in NetRexx
 Automation inter-conversion with Java String class, char and char[] arrays, and numeric primitives (optional)
You can forego the language and use the Rexx Datatype, from the runtime package, in your Java source
Equally, you can decide not to use the Rexx type at all in your NetRexx source
Numeric Precision
(options binary to avoid this and have Java primitive types as much as possible)
Rexx has arbitrary precision numbers as a standard – implemented in the runtime Rexx Datatype.
say 1/7
Parse
 not your standard regexp parser – it is template based
 can do lispy things
12 IBM & I-Bizz IT Services & Consultancy © 2008 IBM Corporation
import java.util.regex.*;
/**
* Static methods to parse out words from a String
*
*/
public class Words {
/**
* Count the number of words in the String
*
* @param str a string containing words that match the regular expression \w+
* separated by \s+
*
* @return int the number of words in the string */
public static int countWords( String str ) {
String[] words = getWords(str);
int numWords = words.length;
return numWords;
}
/**
* Gives a String array containing the parsed out words from the string. The
* method uses the regular expression \s+ to split the string into words.
*
* @param str a string containing words that match the regular expression \w+
* separated by \s+
*
* @return String[] containing the words */
public static String[] getWords( String str ) {
String[] words = java.util.regex.Pattern.compile(« \\s+ »).split(str.trim()); return words;
}
Java can be
very ‘wordy’
For an example, look at this ‘war and peace’ (apologies to Leo Tolstoy) that capitalizes words in a string
(a real world
example)
/**
* Capitalise the first letter of each word in the string. The method uses
* countWords(String) and getWords(String).
*
* @param str a string containing words that match the regular expression \w+
* separated by \s+
*
* @return String containing the original string with the first letter of each
* word in uppercase.
*/
public static String capitalise( String str ) {
String capitalised = null;
int numWords = countWords(str);
String[] words = getWords(str);
for (int i = 0; i < numWords; i++) {
StartingBuffer sb = new StringBuffer(words[i]);
Character c = sb.charAt(0);
sb.setCharAt(0, Character.toUpperCase(c));
words[i] = sb.toString();
if (capitalised == null) {
capitalised = words[i];
} else {
capitalised = capitalised +  »  » + words[i];
}
}
return capitalised;
}
}
It goes actually on for another page
Would be this
in NetRexx
cdr = “foo bar baz”
loop while cdr <> ‘’
parse cdr car ‘ ‘ cdr
line = line car.upper(1,1)
end

Built-in TRACE

for you (and me) who still debug best using print statements – saves time
adds them automatically during compile — fact.nrx
can leave them in and switch off during runtime 8 *=* if number = 0
>>> « 0 »
best way to debug server type software 9 *=* else
*=* return number * factorial(number-1)
can ‘trace var’ to keep a watchlist >>> « 4 »
8 *=* if number = 0
>>> « 0 »
or ‘trace results’ to see results of expressions 9 *=* else
*=* return number * factorial(number-1)
>>> « 3 »
8 *=* if number = 0
>>> « 0 »
9 *=* else
*=* return number * factorial(number-1)
>>> « 2 »
8 *=* if number = 0
>>> « 0 »
9 *=* else
*=* return number * factorial(number-1)
>>> « 1 »
8 *=* if number = 0
>>> « 0 »
9 *=* else
*=* return number * factorial(number-1)
>>> « 0 »
8 *=* if number = 0
>>> « 1 »
*=* then
*=* return 1
>>> « 1 »
>>> « 1 »
>>> « 2 »
>>> « 6 »
>>> « 24 »
>>> « 120 »

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *