REBOL for COBOL programmers
Your own mezzanine
Date written: October 10, 2012
This explains an idea for building your own collections of functions.
The REBOL mezzanine
The REBOL vocabulary is a list of functions. Some of them are "native" functions, which means they are the ones written in C because they are at the lowest level. Others actually are written in REBOL, which can be done because these REBOL functions call upon the native functions and upon other REBOL functions. In other words, some of REBOL is written in REBOL. This would be something like the Micro Focus COBOL compiler which supposedly is written in COBOL. This collection of functions that are written in REBOL is referred to as the "mezzanine."
A COBOL mezzanine
You yourself probably are familiar with this concept, although probably not under that name. You have done something similar if you ever got tired of typing
WRITE PRINT-LINE BEFORE ADVANCING 1 LINES.and put that statement, plus some other commonly-used printing statements, into a COPY file and called it into your source program with the COPY statement.
Your own REBOL mezzanine
As you write REBOL programs, do what you probably did when writing COBOL programs, and look for common operations that you use, or expect to use, over and over again. Capture those in REBOL functions. Then, put those functions you created into one or more separate files, with REBOL headers, thus making REBOL scripts. Then, when you write a new REBOL program, near the beginning of your new script, bring in those common functions with the "do" statement, as explained in the previous section about the COPY statement.
In the code samples that follow on later pages, we will explain this idea in more detail. To save time, we will not hack it out in extreme detail, as we might in a programming class. You already know how to program, so that would an annoyingly roundabout way to get to the desired result. Instead, the code sample below shows what I have in mind. It is a file of functions that I have created because the operations in those functions were things I kept doing, and I could not remember from time to time how I did them. So I made up my own functions that made sense to me and captured the procedures in those functions. Some of these I totally made up and some I harvested and modified from the rebol.org site. At the beginning of a new program, I put the following statement:
do %glb.rThen all the functions defined in that file are available in my new program.
Left-clicking a link below will give a result that will depend on your computer, your browser, and maybe in whether or not you have REBOL installed. You should get either a new window with the code displayed, or a dialog box for saving the file on your own computer, or "opening" the file which makes no sense in this situation. Right-clicking should give you a menu from which you can save it to your own computer.
Global services module
This is a module of commonly-used operations. Some of them are simple, but putting them into this module with our own names makes them easier to remember. Notice the comments in front of the REBOL header. This is an acceptable way to make comments. As mentioned earlier, this will hose up the vim color-coding. However, it can be taken advantage of for documentation purposes as we hope to show later. Note also that all data names begin with a prefix, "GLB-." This is a common practice in COBOL because all data names are global and something like this has to be done. For example, there is a date field in one of the functions, and in any given program there could be lots of date fields. This method of letting all data names in this module be global is not necessarily the approved REBOL way. Another approach would be to make a "Global Services Object" and put all that code into a REBOL object. That concept will be touched upon later. For now, the way we have done it is more in line with the "COBOL way" which is our goal at this time. Use the COBOL way to get yourself going, then move to the REBOL way when you feel comfortable.