REBOL for COBOL programmers
Date written: September 25, 2012
This page discusses the concept of "reserved words" in REBOL and points out some difficulties you might have with code samples on various REBOL web sites.
COBOL reserved words
COBOL is a declarative language. ADD this TO that. MOVE this TO there. The words that indicate what to do, the commands, are reserved words, that is, you can't use them for anything else. REBOL is a little different.
REBOL "reserved words"
In REBOL, there still are words that cause things to happen, like "print," "send," "change-dir." You can see a complete list of REBOL functions (link opens a new window) on the REBOL web site. These are not really reserved words. They are words that have values, and their values are functions that cause things to happen. So what's the difference? You could, if you wanted to make a mess, give the word "print" any value you want, like 6. You would just code
print: 6Then every time the word "print" appeared in your program it would produce a value of 6, which of course makes totally no sense. That would be like, in COBOL, somehow causing the word MOVE to have a value of 6. Then you could code
MOVE 6 TO MOVE. COMPUTE data-name-1 = MOVE + 1. DISPLAY data-name-1and the value of data-name-1 would be 7. This of course is COBOL gibberish.
How to think about words
My suggestion is that in the learning stages, think about the REBOL functions as reserved words. Be aware that if you want to be pure about it, they are not the same, but if you want to get some work done, the reserved-word paradigm will work. As time goes by, you could reread the REBOL documentation and some of the theoretical subtleties will begin to make sense.
Confusion in the examples
You should scan the above-mentioned list of REBOL function so that you recognize them when you see them. Notice that they are nice snappy one-word names. When you read REBOL code samples on the internet, you will see a lot of nice snappy one-word names. You might find those code samples a bit of a shock initially. There are all sorts of lower-case, one-word, snappy names. I have considered that reaction and have the following analysis.
Coming from a COBOL background, you are used to seeing reserved words. Your mind looks for them, as a stable starting point to anaylyse what you are seeing. In COBOL, a lot of those reserved words are computer-related, for example
DATA DIVISION. FILE SECTION. VALUE OF FILE-ID IS data-name-1.Note those words like DATA, FILE, VALUE. They they trigger reserved-word alerts in the COBOL mind. In REBOL, it's different.
In REBOL sample code, there might be a sample to get some data from a file. In REBOL, files frequently are read into memory all at once, because REBOL's original mission was "programming in the small." So you might see code like.
file: %test.txt data: read/lines fileIf you look at that second line, the words "data" and "file" are going to trigger your reserved-word alert. But they are not any sort of reserved words. In REBOL examples, if they want to have a word refer to some data, they will use the shortest and snappiest and clearest word to refer to data, which would be "data." So that reserved-word bias in your head is going to trip you up if you are not aware of it. To make things harder, REBOL customarily uses all lower case. So you have this blizzard of lower-case words, some of which sound like they ought to have some command-like or declaration-like meaning.
In general, become familiar with the list of functions mentioned above, and anything not on that list is a word invented by the programmer to refer to something else.
What we are going to do to make things clearer
These pages will contain some code samples. We are going to use an un-REBOL-like way of coding that might make the samples easier to follow. This probably will be like fingers on a blackboard to experienced REBOL programmers, but this web page does not have a feedback option so all is well. We are going to leave the REBOL functions in lower case, but all the words that we make up, the words that would be considered "variables" in COBOL, are going to be upper case, and usually multi-word words containing a hyphen. These two features, upper case and at least one hyphen, are going to negate that reserved-word alert in your heads. So the above code lines might look like
FILE-ID: %test.txt FILE-CONTENTS: read/lines FILE-IDI would suggest that you do that in your own coding, initially, and then let yourself drift away from it as you experience with REBOL grows.