Documention for: directions.r
Created by: btiffin
on: 12-Aug-2007
Format: html
Downloaded on: 29-Mar-2024

REBOL

Using %directions.r

Source Code by REBOL Technologies
Usage document by Brian Tiffin
11-Aug-2007

Contents:

1. Introduction to %directions.r
2. Using %directions.r
3. What you can learn
3.1 REBOL Header
3.2 Getting a copy of header fields
3.3 Back to %directions.r
4. Credits

1. Introduction to %directions.r

This script demonstrates how REBOL blocks can hold data in a very people friendly format.

2. Using %directions.r

directions.r is more for reading than for doing. This code will load and execute, but doesn't actually do anything beyond defining a variable that holds driver friendly directions for getting to the REBOL Technologies office from San Francisco.

3. What you can learn

The rest of this document is a kind of line by line analysis of the script. Explaining things as it goes. One of the nice things about REBOL is that programs can be pretty short for amount of functionality that is involved.

3.1 REBOL Header

This is rarely mentioned in the usage documents, but REBOL has a very sophisticated script header management system, built right into the language. All scripts have at least a minimal header, which would be;

REBOL []

It is much more professional, and somewhat mandatory for rebol.org scripts, to include realistic entries in the REBOL header.

3.2 Getting a copy of header fields

A nice trick to save a little typing, and to give yourself a template to work from, try;

write clipboard:// form system/standard/script

and you can now paste into an empty text file, all the header fields that are built into REBOL. For more information check out the Headerssection in Chapter 5 of the Core Manual.

At first, if you get used to adding at least a Title, Date, some credit to yourself in the Author field, and perhaps a little Purpose you'll be able to quick scan your own world-class collection of REBOL programs with no time wasted. Later when you update your programs, add a History section to track changes and others will be able quickly scan through your scripts as well.

3.2.1 Extensions

Along with the header fields defined in system/standard/script, you can also define other header fields that can help you keep track of things. If you may want to add Credits, or References, or whatever you may need for tracking. And as you grow your REBOL programming skills, these fields can be accessed inside the program.

3.2.2 rebol.org

When you reach a level of REBOL programming where you wish to share your work, the rebol.org repository also requires a Library header field. More about this extension can be found at Help Contribute.

3.3 Back to %directions.r

After the REBOL header, is the actual evaluated script. In this example script, there is no visible work accomplished. But there is work done. There is a variable defined, To-New-Office created using a REBOL technique with the name set-word!.

You can always tell a set-word by the ending colon ":", without a space, following a variable name. Nearly all programming languages have some form of assignment operation, and in REBOL the main way to define variables is with the set-word! technique. And REBOL being highly reflective, set-word! is actually a data type.

What follows the set-word! To-New-Office: is a block! of blocks. block! is another REBOL datatype, perhaps it's most important, that can hold any other REBOL datatypes.

All these values start out as regular words, and then can be evaluated to give more meaning to the computer. In the case of the directions example, the words in the block are not defined enough for use by a computer, but they make great directions for a driver. REBOL being REBOL, these values can be loaded, manipulated and saved even if they actually hold no real meaning. And REBOL being the cool tool that it is, these values could be made to hold very specific and helpful meaning with just a few more lines of code. For now it's ok to just be amazed that the values are readable both by REBOL and by people.

4. Credits

File

Author

%directions.r

Unknown, from REBOL Technologies

directions Usage doc

Brian Tiffin

Credit also to the rebol.org library team for keeping the repository up and running. Thanks in large part to Sunanda.

MakeDoc2 by REBOL - 12-Aug-2007