Friday, November 24, 2006

Integrate Rexx dialects through BSF4Rexx

It's no secret that I would like to see the various dialects of Rexx converge. Object Rexx has done a marvelous job of being backward compatible with Classic Rexx; NetRexx has done wonders for integrating Rexx and Java by making Java classes out of Rexx, and BSF can integrate interpreted Rexx with Java very well. All can integrate with other code by means of external function libraries or JNI.

Unfortunately and unavoidably, there are some differences in syntax between the different dialects. No big problem, but awkward to explain to newcomers and good for the occasional 2 seconds of astonishment. So in NetRexx the method call is by dot (Datum.getDayOfWeek()), and in Object Rexx it is the famous twiddle, as in Datum~getDayOfWeek. As a consequence, NetRexx does not have Classic Rexx's stem notation, a kind of easy multidimensional and possibly associative array.

Now if we would forego the stem, we could have the dot notation for method invocation in Open Object Rexx, like in every other modern language, but it is probably not to be. I suggested this on the last Rexx Language Association Symposium in Austin, but the points of view seem deeply entrenched.

A recent very positive development is that on my suggestion BSF4Rexx now contains integration for calling NetRexx classes from Rexx without having to instantiate an extra NetRexx object - it will consider a NetRexx string a Rexx string and vice versa. Together with another fix for the handling of exceptions from Java in signal on syntax labels, we should be so very happy that our Rexx and NetRexx can at least seamlessly interface using BSF4Rexx.

Sunday, November 19, 2006

BSF4Rexx Available on the Apple Macintosh

The Bean Scripting Facility is an IBM tool, since donated to Apache, for embedding scripting into the Java VM. There is a version for Object Rexx, that now also is available under MacOSX.

This is because it needs one native component to take care of the interfacing from Java to the (native) ooRexx interpreter - this is sharp contrast to NetRexx, that lives exclusively in the Java universe.

There are some advantages to using Object Rexx to interact with your Java objects. Firstly, it is easier to script OS commands and get the output back into your program. In Java, you need to do a Runtime.exec(), hook the filehandles for output and spawn a tread to look into those. In Object Rexx, the command is executed by putting it into quotes and sending it into an external queue.

Secondly, in Object Rexx it is possible and even easy to create runtime classes and add fields or methods to them using messages. For NetRexx and Java, we need to do awkward runtime bytecode modifications to accomplish the same goal, and still have class loader issues to run the newly composed classes or their instances.

Thirdly, Object Rexx has mixin classes and metaclasses that are simply not there in Java.

But the most important part about this, is that we now have greater freedom and flexibility to quickly implement our architectures or just run prototypes for feasibility studies.

A quick example using jdbc to a database:

/* ooRexx program to demo jdbc capabilities */
-- specify imports
jclass = .bsf~bsf.import("java.lang.Class")
driverMgr = .bsf~bsf.import("java.sql.DriverManager")

-- instantiate jdbc driver

-- make the dbms connection and open a statement
statement = driverMgr~getConnection('jdbc:postgresql:rvjansen','rvjansen','')~createStatement
signal on syntax
statement~executeUpdate("DROP TABLE test") -- catch exception for first time
-- specify query and execute to get result set
statement~executeUpdate("CREATE TABLE test( name char(42), place char(42))")

statement~executeUpdate("INSERT INTO test (name, place) VALUES('Rony Flatscher', 'Vienna')")
statement~executeUpdate("INSERT INTO test (name, place) VALUES('Lee Peedin', 'Wallace')")
statement~executeUpdate("INSERT INTO test (name, place) VALUES('Rene Jansen', 'Amsterdam')")

-- select database content
rs = statement~executeQuery('select name, place from test')
do while rs~next
say rs~getString("name")~strip "from" rs~getString("place")~strip

-- calculate total
rs = statement~executeQuery('select count(*) from test')
do while rs~next
say "BSF4Rexx has at least" rs~getString(1) "fans!"

::requires bsf.cls

Sunday, November 12, 2006

Object Rexx 3.1.1 on the Apple Macintosh

After a few weeks of hard debugging Open Object Rexx on MacOSX is a reality. Tomorrow the CVS repository will be tagged with the release. Some very hard to track down bugs were quashed, while it also became clear that MacOSX's System V Shared Memory call, shmem, leaves something to be desired. More shared memory segments to be exact, because now, just like Postgres, Object Rexx requires you to edit etc/rc to put in some higher values.
While this is ok as a stopgap measure, it is not terribly elegant, and should be avoided by doing the memory management in another way. Another thing to do.

The irony here is that in order to have the programming language I like most running on the platform I like most, I have to do low level work in the language I like least of all, C++. Time we bootstrap the thing.