[REBOL] Re: REBOL Cookbook in Beta
From: carl::cybercraft::co::nz at: 24-Dec-2003 22:34
Hi Steven,
I'll answer a couple of your questions, and leave the others in for
others to have a crack at...
On 30-Aug-03, Steven White wrote:
> An excellent idea. There probably are some things locked in the head
> of the Founder that would be very enlightening to others. Permit me,
> as a perpetual beginner, to try to explain some things that keep
> stumping me.
> They might give others some ideas.
> 1. What must one say? There seems to be a number of functions that
> are important (or critical) in certain situations. The ones that
> come to mind are reduce/mold/remold/compose/form/reform. You can
> look each up in the dictionary to find out what it does, but the
> reverse information is hard to gather: When might you expect to need
> them, what is the purpose behind them, what will not work if I don't
> use them.
> 2. What is the recommended way? This is an area that is being
> addressed by the cookbook, but an idea for the cookbook immediately
> comes to mind. Most programs need to store some data. Some of the
> functions must have been created with this need in mind. I am still
> not sure if there is a recommended way to make a small data base.
> Does one make a block, and then store and load it? Are read/write
> the appropriate functions for storing data with some structure to
> it? The Complete Guide, with its video data base was helpful; is
> that the way one is expected to make a REBOL data base?
save/load, not read/write are the words to use to retain a value's
type. Some examples...
>> save %test.txt now
>> type? read %test.txt
== string!
>> type? load %test.txt
== date!
>> save %test2.txt [I am a block's contents]
>> read %test2.txt
== "I am a block's contents"
>> load %test2.txt
== [I am a block's contents
]
Note the values (meaning the date and block in the above examples) are
saved as plain text files, it being 'load that converts them back to
REBOL values. This is why you'll sometimes see 'load used on strings
and other values, not just files. ie...
>> load "I am another block's contents"
== [I am another block's contents
]
Warning: 'save only saves a series from its index position, not from
its head, and it doesn't save the index, so you need to be careful
with saving series to ensure you don't lose data.
> 3. System words. I see in the library and on the mailing list lots
> of references to system/this and system/that. I have not observed
> any documentation on what these are and what they might be used for.
> 4. Generic words. This might not apply to others, but I come from a
> background of computer languages with reserved words. When I first
> saw REBOL examples, they were very confusing because a lot of the
> words (which I would call "data names") were short little things,
> like "file," that triggered in my corrupted mind the concept of
> "reserved word" or "command." On top of that, they were all lower
> case with no punctuation. Reading through examples was like
> translating Latin. In the few REBOL programs I have written I have
> made all the words of my own invention upper case with at least one
> hyphen, to make it obvious that they are not REBOL functions.
The style-guide in the Core User Guide explains how to write code the
REBOL way...
http://www.rebol.com/docs/core23/rebolcore-5.html
I also started out capitalizing "my" words, but quickly changed to all
lower-case. One advantage of this is it's one less decision to make
per word. (: The other is there really are no reserved words in
REBOL, their meaning being determined when the interpreter looks at
them. The same word can be either data or code, and what appears to
be reserved words can be changed at will by the script, as this silly
example shows...
rebol []
silly-print: func [text /local print][
print: func [string][
prin rejoin ["---> " string "^/"]
]
print text
]
silly-print "Hello"
print "Goodbye"
There the 'print word in the line...
print text
in the silly-print function behaves differenly than the 'print in...
print "Goodbye"
A more normal use of the same word would've been if I'd used 'text
instead of 'string (or vice-versa) in the silly-print function, such
as like this...
silly-print: func [text /local print][
print: func [text][
prin rejoin ["---> " text "^/"]
]
print text
]
There, 'text in both cases has a string value, yet in View/VID 'text
is one of the styles used in a layout. They wouldn't clash in any way
though.
Files and text are so common in computing that repeatedly using words
like 'file and 'text can make things simplier for the programmer, if
used sensibly. I don't have any problem sorting out which 'text is
which in the above function, (the 'print function within it being
easy to spot as seperate from the main body of the code), while the
following one-liner...
for n 1 3 1 [for n 5 7 1 [prin n] print join " " n]
while being perfectly legal REBOL, is probably not a good example of
when to use the same word.
The idea is to use the words that seem right for the job, just making
sure they're local to a function (or in an object) if you're worried
they may over-write global words.
> 5. Uncommented samples. Short, "straight-line" samples are fairly
> easy to understand with the aid of the dictionary, but when a
> scripts gets longer and has some functions, I find it hard to locate
> some firm ground to stand on to get a view of what is going on. I
> sent a sample to the library (popcheck.r, which I see made it in)
> that I wrote at first for my own use, and to make it easy for me to
> remember how it worked I commented it to a level that many would
> consider excessive. I think that for a beginner excessive commenting
> would be one of the most valuable tools for helping him understand.
> Sorry if this is excessively long.
Certainly not excessive and a very clear description of some of the
problems beginners face with REBOL. I seem to remember all of them.
;) I doubt you will remain a perpetual beginner though. It's
strange, but once REBOL begins to click, it seems to get simplier and
simplier. Hang in there and I'll think you'll find this out too.
--
Carl Read