Tips, tricks, and notes on technique for devotees of the REXX programming language as developed, gathered, and outright-stolen during my near-quarter-century of writing in this marvelous tongue.

Tuesday, November 29, 2011

INTERPRET?? WDNNS INTERPRET!

(For those who don't know what 'wdnns' means, it is a reference to a misquote of a line from Treasure of the Sierra Madre and for the rest, you can look it up on the web. The expansion is "We don' need no steenking ..." 'Nuf said.)

It is my firmly held conviction that INTERPRET is almost never required for ordinary REXX processing. Les Koehler has come up with one or two scenaria where it is useful but they are so bizarre that 'esoteric' is a risible understatement. Most uses of INTERPRET run something like this:

I hope I got that right. Since I never use INTERPRET and I don't have a mainframe to test this out, I have to guess as to what the code would actually look like. If I were writing this code, I would use VALUE instead.

parse var parm tag '=' tagval
rc = Value(tag,tagval)

I have also seen entire commands constructed piece-by-piece and then INTERPRETed to cause the command to be executed. Unnecessary.

interpret "ISPEXEC TBCREATE" tblnm blah blah blah

I have never seen a case where the INTERPRET couldn't simply be converted to a straight execution:

"ISPEXEC TBCREATE" tblnm blah blah blah

Anyone with a true instance of a necessary INTERPRET is welcome to present the same here. I'd love to be proven wrong.

11 comments:

I agree the Interpret is way over used but here is one example where I did have to use it. in this code Im displaying an ISPF panel with ISPF Table then reading in the user selection and calling another program with the same name as the selection. I had to build the a string with the varable info and then use INTERPRET to run the command. It was the simplest way i could think of that i could use 2 lines of code and sead it with the varable info.

I once wrote a routine to translate JCL to REXX for use with PL/I Inspect/Plitest. To prevent various users from overwriting the generated REXX ("Ixxxxx", with xxxxx the name of the program) all code was stored into one "Ixxxxx" member per program, and every user had their own section, preceded by their userid as label.

I really cannot find any situation where INTERPRET is needed. Don't get me wrong, but any valid reason I used it was quickly replaced with VALUE. I do a lot of data manipulation and dynamic REXX. INTERPRET may save a line or two of code, but a seasoned programmer would trade one or two lines for readability and maintainability.

Well I am not sure I follow his entire argument ... but I can access any variable with VALUE.

Example:

line = "this is my line"the_value = VALUE("line")

Now the_value is "this is my line"

it works with variables as well:

line = "this is my line"var = "LINE" the_value = VALUE(var)

Now the_value is "this is my line"

You can also assign a value:

line = "this is my line"the_value = VALUE("line","This is my new line")

Now the_value is "this is my line" But the variable LINE has "This is my new line")

Once you know this power ... you can stack the VALUEs x =VALUE(VALUE(some_var)) ... that as long as the other variable contains a valid variable name ... it works just dandy. I like to think of this as the "C" construct of the memory locations.

In my programs, I usually try to keep it simple ... just to make sure it is understandable. Here are some practical snippets of code (forgive me I am doing this by memory).

This is a nice little routine that your program can call if you hit an unexpected call ... you can even include this in a SIGNAL .. but be careful of PROCEDURE and EXPOSE ... but that is another subject

As for the using PARSE ... yes I do that as well (much more often than the example I use) for the simplicity and power. I use the other method for very complex programs that need a bit more debugging mode or even better signal handling.

Building tracing capability into the original is never a waste for any program with at least one CALL.

As for other capabilities, see http://home.roadrunner.com/~mvsrexx/REXX/ and check out REXXSKEL (which I use as a basis for almost everything I write). Yes, it has more capability than I typically need, but like PREGO spaghetti sauce "it's in there".

About Me

Radical Rothbardian libertarian. I believe that government is (at best) an unnecessary evil and that our government is not at its best (and hasn't been since around 1798).
I love to travel but have a hard time coping with the aiport Heimatsicherheitdienst.