Channels ▼
RSS

Open Source

NetRexx: The Original JVM Scripting Language Returns


The point here is, we can stand on the shoulders of others. The more "componentized" these libraries are (for example, using JavaBeans signatures and events), the easier the use and integration is. On the subject of JavaBeans, the NetRexx properties indirect statement generates getter and setter methods for all these properties — something that Java developers depend on an IDE to generate or must write by hand. (While many NetRexx developers use editors, there is a NetRexx Eclipse mode that fills in the need for and IDE, and JEdit also has a very usable NetRexx mode.)

The clear separation between the language and library layers makes it possible to have a lot of options for user interface technology. All user interface technology that works with the JVM also works from NetRexx (including AWT, Swing, or JavaFX), as well as server-based technology (such as servlets, Struts, JSP, or JS)F. Some years ago, I even wrote a Web front-end with Flex with a Tomcat and NetRexx server back-end: Just think about the burning hoops you'd have to jump through to do that in another language.

Syntax

When looking at a NetRexx program, one of the most striking things is the lack of ceremony and punctuation. Its designer, Mike Cowlishaw, is a known opponent of superfluous punctuation. So the repetitive declaration style that plagues C, C++, Java, and JavaScript is absent from NetRexx. There are no curly braces, and semicolons are optional.

Intuitive constructs such as loop … end and select … when … otherwise … end require no explanation. In parameter declarations, the local variable comes first, followed by and equal sign and the type of the variable. When the equal sign and type are omitted, they are assumed to be type Rexx. A method declares a return type whenever it does not return Rexx. This makes for a very relaxed definition of methods. The equal sign can also be used to compare a variable to a type; once you are used to that, it is very natural and you just use it as you would in English.

Runtime: The Rexx Data Type

Type Rexx  (Java integration is such that nothing precludes you from using this from a Java language program) is the historical Rexx invention of having one type for strings and arbitrary precision numbers. It resides in the runtime package netrexx.lang, which is automatically imported for every program so you don't have to think about it (although it requires explicit import if you're calling NetRexx from Java).

String comparison is caseless and humanized in the sense that leading and trailing spaces are ignored. If you want strict comparison, the == operator can be used: It is required if you want to write classes that are not dependent on the NetRexx runtime JAR.

New Features in Version 3.02

After JRE-only compilation was introduced in version 3.01 in 2012 (before that, NetRexx required a JDK for compilation), ease-of-use was addressed in version 3.02, which will be posted to netrexx.org around the time this article appears. New is the closer integration between the Rexx type and the Java Collections Framework.

Where we had to cast a lot in previous versions, and did not have a natural order for elements of type Rexx, these are now recognized and fitted for cast-less operation. We have gone from:

class RexxComparator implements Comparator,Serializable
  method RexxComparator
  method compare(i1=Object, i2=Object) returns int
    i = Rexx i1.toString()
    j = Rexx i2.toString()
    
    if i < j then return -1
    if i > j then return +1
    else return 0

t = TreeMap(RexxComparator())
i = t.keySet.iterator
loop while i.hasNext
	r = Rexx i.next() 
end

to

t = TreeMap()
t.put('foo','bar')
t.put('baz','frob')
i = t.keySet.iterator
loop while i.hasNext
	r = i.next() 
end

Here, the keys are automatically put in the order of the now built-in comparator, and variable r will be of type Rexx. So, when getting elements out of the collection, no cast to Rexx is necessary.

This is generic handling without the syntax. All Rexx type container facilities (the associative "indexed strings" functionality) is usable from the elements in a collection, as are the NetRexx string methods.

Also, to ease integration in products that need on-the-fly compilation or interpretation of a string of code, an API was added to the existing, file-based compiler API. It enables program execution of a string containing the source, as in:

import org.netrexx.
/* NetRexx compile from string example  */
programstring = "say 'hello there via NetRexxC'"
NetRexxC.main("myprogram",programstring)

New methods b2d() and d2b() enable conversion of binary strings to decimal, and decimal strings to binary. For example:

'01110'.b2d == 14
'10000001'.b2d == 129
'111110000001'.b2d == 3969
'1111111110000001'.b2d == 65409
'1100011011110000'.b2d == 50928

'129'.d2b == 10000001
'129'.d2b(1) == 1
'129'.d2b(8) == 10000001
'127'.d2b(12) == 000001111111
'129'.d2b(16) == 0000000010000001

Also, the Rexx type can now be subclassed, a long-standing wish of our user base.

Code Examples

NetRexx is written entirely in NetRexx. Other examples can be found at rosettacode.org, which catalogs various algorithms and puzzles with equivalent implementations written in numerous languages. The examples are also included in the NetRexx distribution, as are others that show nearly every aspect of the use of NetRexx in application software, including all the IBM NetRexx Redbook example code. I expect these examples will convince you that NetRexx is one of the most original and productive alternatives to Java on the JVM.


René Vincent Jansen is the current president of the Rexx Language Association; he was a systems programmer for decades and now manages technical teams in infrastructure and application projects. He likes everything that just works.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video