REBOL BEGINNERS TUTORIAL

EXECUTIVE SUMMARY: REBOL is the cocaine of scripting languages. I love it and I can't stop, yet at the same time I hate what it's done to me and the depths I've gone to to get more of it.
Home
Lessons Learned:
A. My bad: The expected procedure is read source code until you get it. There are no known tutorials except this one, which is why I decided to write it. You get a dictionary, users guide, users manual, the how-to, the faq and the archives at rebol.org. You'll be clicking the mouse button a lot if you want to read those. There are also a couple documents that mislead you about how easy it is to use rebol.

B The words:
word
function
value
object
are used so interchangably, so vaguely, so often that they become meaningless. Anything can be anything in REBOL, except when it's not.

C. My bad: It is actually a good idea to start with Chapter 1., "Values" of the Users Guide.
C.1 My bad: Some of my questions were answered in the FAQ, but it was greek to me at first. The whole point of this page is the docs, after all.
C.2 My bad: Alright already, I changed the name of the link. You'd think some people didn't know where babies come from.

D: Rebol bad: There are two different documents, Users Guide and Users Manual. They are different, which isn't apparent at first. I suspect is is because the link called REVISED USERS MANUAL takes you to USERS GUIDE v2.2.0, while the link USERS GUIDE takes you to USERS GUIDE v2.1.2. Erin tells me the old guide is going away soon, which is a shame since it prints out in a fairly compact 46 pages. The User's Manual there is no way to print out unless you want to click the mouse button for hours at a time. I still haven't printed it. I'm up over 200 pages of paper now, all html pretty graphics that manages to squeeze two whole commands to a page. What ever happened to the flat ascii text file?

Well, you're not reading this to hear me bitch, on with the show.
REBOL 2.2.0.3.1, running on a Wintel 98 box.

E: PUNCTUATION (DON'T SKIP OVER THIS PART)
1. No punctuation =
if data, get value
>> system/user/email
== jamaicamon@cannabismail.com
if function, do it
>> halt
>>
2. the colon
2.1 after = assign next characters to that word, like the LET statement
BASIC LET MADEUPWORD = 3
REBOL
>> MADEUPWORD: 3
== 3
2.2 before = get value, but don't apply it. Kind of pointless for short examples.
>> madeupword
== 3
>> :madeupword
== 3
>>
Key idea is:
Same as evaluating plain word for data values, but NOT same for words whose value is a function. "Get"ting a function, doesn't evaluate it. For example:
>> greet: func [name] [print ["Hello," name]]
>> greet "jamaicamon"
Hello, jamaicamon
>> aloha: greet
** Script Error: greet is missing its name argument.
** Where: aloha: greet

REBOL is unhappy because evaluating 'greet requires giving it an argument. However...
>> aloha: :greet
This sets 'aloha to the current value of 'greet, without trying to evaluate the function. Following this, you can...
>> aloha "jamaicamon"
Hello, jamaicamon

Good point. I'm not actually up to the >>madeupword: func [ kkk [ jjj ]] stage yet, I'm still at the >>madeupword: read file://... stage. Brings up another important point, I'm beginning to see which commands are more used (func, reduce, mold). In a dictionary all 300+ words are equal, so you can't spot the important ones.
2.3 the colon also shows up in protocols (file:) and the time data type.

3. ' = literal, much like quote marks in english, perhaps you want to print the word 'delete instead of do the word delete. 'word refers to the word itself, instead of its current value.
>> 'delete
== delete
>> delete
** Script Error: delete expected target argument of type: file url.
** Where: delete
>>

4. ! = datatype model "DO this TO that"
used with MAKE and one of the datatype keywords. See below. Important.
No. The ! character can be used in the name of a word.
>> greet!: func [name] [print ["Hello," name]]
>> greet! "jamaicamon"
Hello, jamaicamon
By convention (but not rules of the language!) used to distinguish between names of datatypes and queries to see if something is of that datatype.
>> type? 123
== integer!
>> integer? 123
== true

5. Brackets [] like a parenthesis in math. Also used for paragraph indent [ and unindent ]
6. Paranthesis () like [], but is evaluated immediately
7. " " double quotes = generally text (single quotes can too)
8. / = forward slash = a path evaluation
9. ; = semi colon = comment ; this is a comment
10. ^ = carat = used to insert ascii values close. Used to "escape" values in strings for special treatment.
>> print "these^-words^-have^-tabs^-between"
these words have tabs between
>> print "these^/words^/have^/newlines^/between"
these
words
have
newlines
between
>> print "these^(line)words^(line)have^(line)newlines^(line)between"
these
words
have
newlines
between
>> print "these^Iwords^Ihave^Itabs^Ibetween"
these words have tabs between

10. , = comma = Used as alternate "decimal point" (per European usage), the comma IS NOT used to separate data values.
>> block: ["my" "dog" "has" "fleas"]
== ["my" "dog" "has" "fleas"]
>> bogusblock: ["my", "dog", "has", "fleas"]
** Syntax Error: Invalid word -- ,.
** Where: (line 1) bogusblock: ["my", "dog", "has", "fleas"]
>> 1,25 + 2,50
== 3.75

11. @ = unknown if used
12. \ = unknown if used (no case escape character?)
13. $ = unknown if used (outside the money datatype)
14. brit pound sterling sign = unknown if used

F: DATATYPE
The REBOL they start out with everything is a value, what they really mean is a datatype:
No. A datatype is a class of values that exhibit the same behavior. Therefore, every value is/has a datatype. (Even datatypes -- which are values -- have a datatype!)
Rebol Bad: Users Guide v212 Chapter 1, "Values" the paragraph headings all start "Integer Values", "Decimal Values", "Time Values" etc. but they are talking about datatypes. They really need to get a handle on the differences between word, function, value and object so they can explain it to others.
Thes is straight from the book, so won't bother to define them:
integer!
decimal!
time!
date!
money!
logic!
char!
none!
string!
binary!
email!
file!
url!
issue!
tuple!
tag!
block!
hash!
list!
paren!
path!
words!
REBOL DECIDES FOR YOU WHAT YOUR DATA TYPE IS!!!!
>> test: 123
== 123
>> type? test
== integer!
>> test: $123
== $123.00
>> type? test
== money!
>>
Also, there is what I call the system-call, the low leve iface to the kernel. They hyphenate it, smt-port
This is the kind of info that should be on the front page in bright red letters instead of on the back right after 'monosodium glutimate'.

G: KEYWORDS
Which I define is a word you type at the prompt that does something. They seem kind of confused by this concept at REBOL. Depending on what docs you are reading, it means any or all of these things: a native, (built in functions), (internal language), (words with predefined values), (keywords), (keyword is a special purpose control symbol), (function that executes on the system processor), (predfined context) or what you find in (system/words).

"Another source of errors we will address is the possibility of accidentally redefining a word that is part of REBOL’s vocabulary." or, they could mean short text strings of the sort often found in an english language dictionary returned to you by the kernel (system processor).No. A word is more like a name in ordinary speech. It simply refers to whatever value it was defined to (assuming it has been defined). Therefore, Depending on the current context, a word may have any of these as its value: a simple data value, a data structure, a function (defined in REBOL itself), a native (a function predefined within the REBOL interpreter, ...

But the real thing is I want them sorted into functional groups, like every other tutorial in the universe. Here's my poor attempt so far.

Arithmetic operators: The familiar +,-,/* as well as many more. All also have english duplicates such as add, subtract etc.
Series specific functions: Rebol is very big on series, data entries inside of brackets.
next, back, pick, skip, tail, head, length?, index?, head?, tail?
find, select, sort, forall,foreach,forskip, match (2 series against each other),make,copychange,insert,remove,clear,none?,first,second,third,forth,fifth and last
evalutaion

contexting: haven't messed with this
Think of a context as being like a private dictionary. Contexts allow words (well, at least, words spelled identically) to have different meanings in different settings. For example: >> print 1 + 2 3 >> print "Hi!" Hi! >> prin "x" prin "y" prin "z" print "- that's all!" xyz- that's all! That uses 'prin and 'print with their global meaning. But in >> bufferingfunction: func [/local buffer prin print] [ [ buffer: copy "" [ prin: func [value] [append buffer form value] [ print: func [value] [append append buffer form value "^/"] [ print 1 + 2 [ print "Hi!" [ prin "x" prin "y" prin "z" print "- that's all!" [ buffer [ ] >> print bufferingfunction 3 Hi! xyz- that's all! the function creates a context in which 'prin and 'print have a different meaning. > use =

SCHEMES (protocols)
SMTP POP FTP HTTP NNTP FINGER

FUNCTIONS (KEYWORDS, whatever). The CONTEXT is the set of all defined words.
a function accepts "values" as "arguments" and return a "value" as a "result"
How do we look up the words defined by REBOL? Both globally defined words as well as words defined in a script can be retrieved from the path first system/words. foreach word first system/words [ this-type: mold type? get/any word: in system/words word if all [ system/words/any [ this-type <> "unset!" ; ignore unset values any ; unless we got the /any refinement ] system/words/any [ not :tester ; unless we aren't using tester, tester get/any word ; check with datatype test function ] read = (reads from a) %file,...
write = (writes from a) %file,...
load = (analyze a value, determine its datatype, convert to that data type)
save = (convert and save in appropriate format for that datatype)
echo = to file and console >>echo %test.txt
trace =
open =
close =
do =
insert =
reduce = [] evaluate all expressions in block as single expression
'do (when applied to a block -- it can also be applied to strings and files) evaluates all expressions in the block and returns the last value as its result. 'reduce (when applied to a block) evaluates all expressions in the block and returns a block containing all the values. compose =
input =
exists? =
delete = remove files
do [] = block evaluate

if = logic condition , block to evaluate if true
either = with two blocks
loop =
repeat =
break =
until = returns true
for = accidentally is same command as in BASIC
make = create an object, create new function
extend,use
try [] = attempt to do a function

LOGIC CONDITIONS
true, false, on, off, yes, no

General Nomenclature
1. A function comes before an argument ;prefix function
>> print 'this
this
>>

or
>> print 'one 'two 'three
one
== three

(maybe better not try that one)
The entire line is treated as if it were a block. After the input line is translated to a block, the interpreter will 'do that block. So... 2. Or else it comes between two arguments ;infix function
no example

Hmm... infix operator, actually. >> type? get to-word "+" == op! H. THE WHOLE 'SYSTEM' THING
You'll quickly develop an adversarial relationship with the system processor, since it is completely undocumented and I think REBOL thinks you are crossing over into proprietary territory.
Anyway, I guess you talk to the system with functions
function (a series of values that exist temporarily)
and it talks back to you with objects
object (a series of values that exist defined permanent)
Which is different from a script evaluating, which is kind of like functions talking to each other, except when they need an object from the system processor.
Environmental variables (with a little help from erint@rebol.com)
REBOL calls these 'system objects' and you can find them by looking at a tree under system/
don't use the function source, or the function print, don't work
help works
Here's a quick look
>>help system/ = invalid path
>>help source/words = locks up rebol
>>help system = system is word of value: ?object?
>>help source/words = locks up rebol
>>help system/schemes = long dump of of good stuff
>>help system/options = short dump of good stuff
>>help system/user = short dump of name, email, and (functions defindined in user.r?)

There are others (system/network, system/version, system/product), but I don't really have time to type >>help system/a
through
>>help system/zzzzzzzz at this point.
You'll probably want to dump these to a text file for study
>> echo %schemes.txt
>> help /system/schemes
>> echo none ; echo off and echo no don't work. That would be consistent logic, silly.
But what started me down this road was I wanted to find out environment variables like my home directory. I'll skip over the part in between. Just because I have suffered for my art it doesn't mean you have to:
(Note: Garbage is not my opinion of REBOL, I just have an old habit of keeping a directory called c:\garbage that I always put new files in to. If I go back later and don't remember what they are I'll assume I would have moved them out of that dir if they were important.
WHAT IS MY HOME DIRECTORY?
>> print system/options/home
/C/garbage/
>>
I WANT TO CHANGE THAT TO C:\TEMP
>> make object! [system/options/home: %/TEMP/]
>> print system/options/home
/TEMP/
>>
THERE IS ALSO A SIMPLER WAY >> system/options/home == %/C/garbage/ >> system/options/home: %/TEMP/ == %/TEMP/ >> system/options/home == %/TEMP/ >> MISCELLANEOUS

There are a few good scripts out there that show you something about the system, you'll have to wade through all the ones that show you how to read email. huh.r is a good one. There's more I haven't looked at yet.
OPENING A SCRIPT FROM THE COMMAND LINE EXAMPLE
( The file is in c:\windows\desktop\rebol and is called browse-system.r )
>> read ** Script Error: read expected source argument of type: file url object block.
** Where: read
>> read file
** Script Error: file has no value.
** Where: read file
>> read file://
== [%BOOTLOG.TXT %COMMAND.COM %SUHDLOG.DAT %DETLOG.TXT %MSDOS.--- %SETUPLOG.TXT %WINDOWS/ %NETLOG. TXT %RECYCLED/ %MSDOS.SYS %CONFIG...
>> read file://c/
** Access Error: Cannot open /C/c/.
** Where: read file://c/
>> read file://windows
** Access Error: Cannot open /C/windows.
** Where: read file://windows
>> read file://windows/
== [%SYSTEM/ %COMMAND/ %WINSOCK.DLL %PROTOCOL %INF/ %TELEPHON.INI %HWINFO.EXE %NETDET.INI %SMARTDR V.EXE %SYSTEM32/ %HIMEM.SYS %RAMD...
>> read file://windows/desktop
** Access Error: Cannot open /C/windows/desktop.
** Where: read file://windows/desktop
>> read file://windows/desktop/
== [%Shortcut%20to%20WorldNet.lnk %%28D%29.lnk %attwebpage.htm %mylinkd.txt %NScpape.lnk %Add-Remo ve.lnk %mooreslaw.doc %Profree.ln...
>> read file://windows/desktop/rebol/
== [%fallout.doc %rebol.baddocs.doc %rebolhate.doc %options.txt %Cls.r %Definitions.r %Desktop.r % http.txt %what-values.r %browse-s...
>> read file://windows/desktop/rebol/browse-system.r
== {REBOL [
Title: "System Object Browser"
Date: 3-Jun-1999
Author: "Bohdan Lechnowsky"
Email: bo@rebol.com
...

BOOTING
start rebol, it runs
rebol.r
user.r

BROWSE-SYSTEM.R
aka "DA DO READ READ RUN DA DO READ RUN"
Theres a good script to let you look at your 'system object' (aka environment variables aka settings..)
And get a feel for what REBOL stores and what it's called in REBOLspeak.
I could get it to run from the command line but once I quit out it I couldn't restart it without quitting REBOL again. This can trip you up since on a normal start up:
NNTP protocol loaded
Script: "REBOL Extended Definitions" (3-Sep-1999/17:55:08)
Script: "User Preferences" (5-Jan-2000/6:13:31-5:00)
>>

while if you start with browse-system.r
NNTP protocol loaded
Script: "System Object Browser" (3-Jun-1999)
=== system ===

Rebol.r and User.r do not get loaded, and you won't notice until you start looking for your email etc. and can't find it. I tried restarting it from the command line various ways, passing it parameters
>> read file://windows/desktop/rebol/browse-system.r 0
>> read file://windows/desktop/rebol/browse-system.r 1
>> read file://windows/desktop/rebol/browse-system.r -do

then got warmer with
>> do read file://windows/desktop/rebol/browse-system.r
before hitting on
>> do file://windows/desktop/rebol/browse-system.r
Hey, this is how the new user mind works.