REBOL Tutorial, Part 2
Let’s start by opening up the tutorial in another browser tab or window.
At the beginning, Nick Antonaccio gives several demonstrations of simple REBOL programs that perform tasks that could be useful. Of course, for each of these, in real life, one might want to improve them. But they serve their purpose. In few other languages can such short snippets of code perform these tasks. In some languages, something like displaying one’s IP address (such as is seen on the public Internet) can take pages of code and external libraries to accomplish. This is the beauty of functional languages in general, and REBOL in particular.
REBOL is designed from the beginning to be used in modern operating systems. Thus, in section four, where we first start looking into the code to see what it is doing, we have this example:
view layout/size [] 400x300
I want to note a few things:
- the “/size” and “400×300″ parts are a refinement, REBOL’s name for built-in option, of layout. This allows the programmer to specify the size of the window that is created. You could create this window without specifying the size. I just did, and it was very small, with little spots where the close and resize buttons would otherwise be.
- the “[]” is necessary. The [ and ] characters specify blocks where other content may be placed within the command. In this case, buttons and other contents of the window would be specified in the square brackets.
- the “view” is the part that activates the layout, making it visible and usable.
- Although I have been playing around with REBOL from time to time since the late 1990s, I have come further in the last two or three weeks with this tutorial than I ever have before. I sincerely hope that you will continue to join me on this journey.
- REBOL is pronounced like in rebel, although I still prefer to say it like in ree-ball.
- Learning a little bit of REBOL is making me curious about functional-style languages, something that never happened before. Hopefully, my friend Dr. Tony and I will find a way to use this in his inner-city neighborhood-building program, as well as a similar program in Pasadena.
If you have not yet begun following along, start REBOL and be sure you have the tutorial open too. These examples show just how simple it is to create a GUI interface.
By way of comparison, if you have ever used Java’s Swing library to create a window, you know that you have to create a JFrame, get its contentPane (before Java 1.5 / Java 5), and then attach whatever widgets before you make the JFrame visible and active. Each of those components that you use is a separate instance of a Java class and several lines of Java code. This is not said to put Java down. In some ways, Java may be more understandable, although I think they have complicated it so much that it is less and less understandable with each version.
Look what happens when you add button "Click Me" to this example. You now have a button. Adding button "Click Me" [alert "Clicked!"] made the button fully functional, popping up a dialog box with “Clicked!” in it.
Next he adds a dialog to get some data from the user and then uses that data in the button’s dialog box. He follows this up with creating a file with the data in it. Do you see this? All in two lines of text, where it could be several pages of text in some other languages. And unlike Perl and Python and Ruby, there is no external library that must be installed to enable GUI programming. (I should note that Python and Ruby are two of my favorite languages.)
In pretty short order, we start displaying images downloaded from the Internet, saving said image to the local hard drive, and displaying that saved image. None of these examples are longer than two or three lines, with little boilerplate code to bloat it. This is one of the chief advantages that I have seen in my reading about REBOL (and such languages as Common Lisp and Scheme): code can be short and efficient, an elegant expression of the task at hand.
We might say that REBOL allows the programmer to exercise economy of effort. By this, we mean that it often takes less effort to obtain a given set of results. Let us join hands for this journey. Hopefully, this time next year, we will be skilled at using REBOL to “scratch the itches” in our lives.
technorati tags:REBOL, tutorials, newbie, programming
Blogged with Flock


