Skip to main content

My favorite feature of REXX and the one I miss most in other languages

I'm a pretty relaxed programmer.   I like a programming feature that is so intuitive that I can remember how to use it without a reference manual and without Google.

REXX was invented to make string processing easy, at a time when there were few choices.   That's an apology because you won't see things like regular expressions natively in REXX.  But here's the kicker - you don't need them.  REXX has a simple syntax that is easy to remember and use.  It is not as powerful as PERL or Python - it was not made for that audience. It is a tool that lets regular people be productive without remembering a ton of rules.
s = 'this is my string'
if I want the 3rd word, type :
say word(s, 3)
dt = '10/20/2030'
The feature I like most is the "parse var" command.
The basic form is:


parse var sourcevar target1 separator target2 separator2 ... .
The '.' character represents a throwaway item.  The last target in the command gets the remainder of the string. That's it (mostly).

So, if I want to convert this string (dt) into three variables representing day, month, and year:
parse var dt d '/' m '/' y
This creates 3 new variables: d, m, and y.

What if I have this string?

dt2 = '10-20-2013'
parse var dt d '-' m '-' y
Piece of cake.  Ok, what about a US phone number?


ph = '(123)456-7890
parse var ph '(' area ')' nxx '-' line
Again, easy peasy.

So, what happens if the user types something that doesn't match? Well, let's try:

ph2 = '(123)4567890

parse var ph2 '(' area ')' nxx '-' line

since there is no dash, all the values go into nxx and line is blank.

The net result is that you'll want to make sure you got the right information back -- as you would  with regular expressions.

Oh and you can use parse var to pull apart fixed format strings as well.  I didn't use that as often so I can't remember the syntax -- except that I remember it uses numbers.

Update: I looked it up. Again, easy peasy.  Just put a number before each field. That's the starting position, where one (1) is the first position in any string.. As always, if you want to ignore, use a '.' as variable name. use a plus sign ('+') to indicate a relative distance from the last number.  Last field gets the remainder.

parse var ph 2 area +3 . +1 nxx +3 . +1 line +4 .

You can read this as:
parse variable ph, start at position 2 using area take 3. Using the throw away, take 1. Using nxx take 3. Using throw away take 1. Using line take 4 and ignore the rest.

Oh and you can drop the dots if you don't want them. The rest remains the same.

With regular expressions, you have so many dialects  (Regex Buddy supports a whole bunch), you're likely to get them wrong (see Zawinski's observation on Regular Expressions).

To me, this REXX syntax is much simpler.  Now, of course, this kind of parsing doesn't actually have the full power of regular expressions.  But then again, it doesn't have the complexity either.

The fixed format parsing is the most complex form of this syntax and it isn't used that often anyway.

REXX is available on all IBM operating systems and for free on Linux, Windows, and derivatives. You can find implementations at the REXX language association website (http://www.rexxla.org ). It is an ANSI standard language with a description at http://www.rexxla.org/rexxlang/standards/j18pub.pdf


Comments

Popular posts from this blog

Using Fossil SCM with Jenkins CI

Currently, there is no SCM plugin for Fossil in Jenkins. I've been coding one but it's not yet ready.

Update: I have permission from my employer to open source the plugin. Now if only I had the time...

Update 2:  I've created a github repo for my code: 
https://github.com/rjperrella/jenkins-fossil-adapter

It turns out, you should be able do a pretty good job of integrating Fossil into Jenkins without using such a plugin.

Here's my idea:

For now, you should just need the Xtrigger plugin. This plugin is capable of triggering a build based on a number of things changing. Among them, a web-addressable piece of content in XML.

Fossil is able to generate RSS feeds trivially.

On the Fossil machine, you'll want to start the fossil server as usual:

$ fossil server --port=1234

On the Jenkins machine, you'll simply install the Xtrigger plugin and set it to trigger a build, by polling the following URL for changes:

   http://<FOSSILMACHINE>:1234/timeline.rss?y=ci&n=0

T…

Why Fossil-SCM is an excellent choice for introductory programming courses

Fossil SCM for introductory programming courses The use of source control management (or version control - take your pick) is an important skill for new programmers to adopt.  It is expected that all programmers use SCM in their daily jobs, in order to coordinate changes among team members.  Thus, getting beginners to adopt good habits early should be a goal.

While GIT (git-scm.com)  is certainly the dominant source control system of today, I believe instructors of introductory classes in programming should consider an alternative called Fossil (fossil-scm.org).

Fossil has several compelling advantages in education over GIT.  You will see that I value the practical aspects of Fossil even more than its technical capabilities.  After all, an instructor has a limited amount of time to have an impact and they don't want to waste time doing technical support on a tool that is too complex.  Helping one or two people is fine but helping 30 can be a real burden.

Simple installation and …

So you want to use Fossil DVCS as your SCM solution? Here are some first steps.

First steps when using Fossil SCM.

Download the executable from http://www.fossil-scm.org

Depending on your programming language and operating systems, you'll want to make sure you ignore certain kinds of file extensions.

You might want to create a configuration file and store it in fossil for use in other fossil setups.  The configuration file goes into the top level directory under a folder called ".fossil-settings".  The filename matches the configuration setting, thus it is called "ignore-glob".

For unix/linux, I would ignore the following file extensions (you can put one per line or separate them with commas. I'll use the per line convention here.)

*.o
*.a
a.out
*~
*.pipe
*.tar

For Windows, I would ignore these:

*.obj
*.exe
*.lib
*.tmp
*.$$$


Next, you'll want to decide on binary file for the purpose of merging. These go in the .fossil-settings/binary-glob file:

*.jpeg
*.jpg
*.gif
*.bmp
*.mpeg
*.mpg
*.avi
*.flv
*.ico

Typing fossil settings binary-…