REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 5-May-2010 Edit History |
To create or modify scripts, you will need a text editor and to know some basic rules.
You can write REBOL code and data in just about any form you want.
Here are some basics:
Spacing | spacing is used to separate values and words, just like in English and other natural languages. You will need to keep this in mind. For example, a - b is not the same as a-b. |
Indentation | can be whatever you want, but we suggest tab size of 4 spaces, or set your editor so actual tabs are 4 spaces. |
Line-length | lines can be any length, but remember that not everyone has a wide screen. Good idea to keep them less than 100 chars wide. |
Line-termination | any terminators will work (LF, CR, CR-LF) and REBOL can easily convert termination if you need it to do so. However, once loaded into memory, REBOL strings normally use just LF. That's our standard. |
Brackets | are used for blocks (collections or lists of words and values). Normally, bracket's begin on the same line with their associated expression and end brackets line up with the beginning of that same expression. |
Braces | are used for multiline strings. If you use braces, keep in mind that they include any indentation on the lines that follow. (See trim for an easy way to adjust them.) |
Example of the above:
if now/time < 12:00 [ print "Good morning!" ]
Notice the spaces around the greater-than symbol, the "[" on the same line, and the 4 space indentation of the next line. Then the "]" appears on a separate line, indented to the same level as the if that it belongs to.
For more, see the large example at the end of this page.
We also recommend that you take a look at the style guide found in scripts: style guide section.
REBOL 3.0 accepts UTF-8 encoded scripts, and because UTF-8 is a superset of ASCII, that standard is also accepted.
If you are not familiar with the UTF-8 Unicode standard, it is an 8 bit encoding that accepts ASCII directly (no special encoding is needed), but allows the full Unicode character set by encoding them with characters that have values 128 or greater.
Most modern text editors handle UTF-8. If your editor does not support it, then you may need to stick with only ASCII characters.
Also note: do not write scripts with Latin-1 or other "code-page" encodings. They will not work properly.
R3 files are stored in ASCII text or UTF-8 formats and use a .r suffix (file extension).
However, the .r suffix is not critical, and it's not enforced. For example, your file can be .txt, .cgi, or even .html and as long as a REBOL header can be found, it will be loaded.
Note that suffix is often useful for file associations or MIME types that can automatically run your scripts or open the preferred text editors. These associations are supported when you install REBOL, but that is an option, not a requirement.
There are a lot of editing programs out there, and some are better than others.
Basically, any editor that can edit and save text files will work. Just be sure that you save the file in ASCII or UTF-8 text format. (If you must use a word processor for some reason, don't save as a .doc.)
In addition, if your editor supports code, then it can help with indentation. It may also provide syntax coloring which can be helpful for noticing problems, like missing quotes.
It also helps save development time if your editor supports a keyboard shortcut to run REBOL with the current script as input. For example, we like to use CTRL-E to mean save and evaluate a script.
A long list of REBOL editors is available, but here are a few of the most common:
You can even use web-based text-area editors, although beware that they do not handle tab spaces very well.
REBOL does not support an IDE at this time (although we want to add one in the future.)
You can use existing IDEs, such as Visual Studio, XCode, Eclipse, KDevelop and others.
As we noted above, scripts are free form. However, to evaluate a script with do does require a REBOL header.
The general pattern in most scripts is:
REBOL [ Title: "This is the header" Date: 10-Feb-2009 ] ;-- Data definitions: name: "Bud" ... ;-- Function definitions: do-it: func [data] [print data] ... ;-- Main code: do-it name
Of course, this will vary, depending on the purpose of the script.
Here's what a typical REBOL script looks like. Note the header at the top, and also that the script can hold nicely formatted data, multi-line text. It's easy to read and nicely formatted.
REBOL [ Title: "REBOL Ale" Date: 30-Oct-1998 File: %beer.r Purpose: "Recipe for a rich, malty, copper brew." Author: "Anonymous" ] Ingredients: [ 0.5 lb. "Toasted malted barley" 7 lb. "Amber malt extract" 1 lb. "Crystal malt" 1.5 oz. "Northern brewer hops" 1 oz. "Cascade hops" 1 pkg. "Ale yeast" 5 gal. "Sassenranch water" ] Instructions: { After toasting barley to red color (15 minutes), boil it in 1/3 of the water for 10 minutes along with the crystal malt. Add malt extract and brewer hops, then cook 55 minutes. Add cascade hops and remove from heat. Sparge into remaining cold water. Add yeast when cool. Rack twice. Wait four weeks. Cheers to the revolution! } ;-- Conversion to Metric Units: Equivalent: [ gal. 3.8 l. ; liters per gallon lb. 0.45 kg. oz. 28.3 g. ] foreach [amount units description] Ingredients [ conversion: find equivalent units either conversion [ print [ amount * second conversion third conversion description ] ][ print [amount units description] ] ] print instructions
To see hundreds of other examples, visit the REBOL.org archive.
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |