r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Rebol School] Rebol School

Anton
11-Apr-2006
[228x3]
Yes, there is an automatic garbage collector. (you can force it with 
RECYCLE)
Values are released when there are no more references to them (and 
the GC decides it's time to do a recycle).
Words, however, even though they are values, cannot be destroyed. 
If you go into the console and type some random words like "aklsdf", 
you can see them at the end of  first system/words, and they will 
never disappear from this list, even if the words are unset.
BrianH
11-Apr-2006
[231]
A word is basically a value that can be put in a value slot. This 
value includes a pointer to a symbol and a pointer to a context.


A symbol is like a string that is only stored once. The symbol that 
is pointed to by a word is the same symbol (same chunk of data) as 
that pointed to every other word that is made up of the same characters 
as the word (case-insensitively).


A context is like a map from symbols to value slots. When you create 
a context it has the specified set of symbols associated with it 
and each one of these symbols has an associated value slot. When 
you bind a word to a context, you change the context pointer of a 
word to point to the context. If you try to bind a word to a context 
that doesn't include the word's symbol, the bind fails silently and 
the word is unchanged. With the exception of system/words, all contexts 
are of fixed length once they are created (for now).


If the word's context pointer is not set, the word is considered 
unbound. If the corresponding value slot in the context the word 
is bound to is supposedly empty, the value slot really contains the 
unset! value, and the word is considered unset.


(Current implementation) Every word you create is added to the system/words 
context, which expands to include it if it isn't already there. Currently, 
system/words has an upper limit of 8000 words. This effectively means 
that the words your script uses must not exceed 8000 unique symbols, 
including those used by the runtime.
Anton
11-Apr-2006
[232]
I've made a document here that kind of explains words and values. 
It doesn't explain the same word in different contexts though.
do http://www.lexicon.net/antonr/rebol/doc/rebol-values.r
BrianH
11-Apr-2006
[233x4]
Currently, object! and function! types have contexts associated with 
them, and some natives (such as USE) create contexts internally as 
part of their operation.
Anton, my explanation above does cover the same word in different 
contexts. Contexts don't really contain words (except as values in 
the value slots). You can think of a context as a hash full of references 
to symbols and a block (of the same length) that contains the value 
slots corresponding to those symbols. A word is just a value that 
points to a context, and another word can point to another context, 
even if both words also point to the same symbol.
Peter, series values are really a pointer to the series data and 
an offset. When you assign a series value to a word, that pointer 
and offset are copied into the value slot that is currently associated 
with that word (until it is bound to another context). The actual 
series data pointed to is unchanged, though.
An integer value like 4 is actually contained in the value slot rather 
than pointed to by it, so when you insert a 4 in a block or assign 
one to a word, it is copied into the new value slot. Value types 
like this are called immediate values.
Pekr
11-Apr-2006
[237x2]
I think that it would be good to have visual drawing - sentences 
as "symbol that is pointed to by  a word" is kind of abstract for 
newbies. And what bothers newbies? When the series is unique and 
not shared. I know cases where I better use 'copy, because I am not 
really sure, what rebol will do ...
I don't know single person, who would not run into troubles because 
of that ... I once even saw Carl's script, where changing border 
of one button changed them all ;-)
BrianH
11-Apr-2006
[239]
I agree about the pictures. Too bad AltME uses variable length fonts, 
or I could do ASCII art. It's a good thing that denismx already told 
us that he is familiar with C++, so I don't have to explain what 
I mean by a pointer or a string here.
Pekr
11-Apr-2006
[240]
I know, nothing against what you describe, I just wanted to point 
out to possible troubles and mistakes by newbies, and am trying to 
find out, how to avoid it ....
BrianH
11-Apr-2006
[241x2]
I just hope he can translate for his students.
Perhaps we need to make a REBOL-in-REBOL, if only for the sake of 
teaching.
denismx
19-Apr-2006
[243]
I'm starting to sort the concepts out, cross-referencing several 
explanations. I will have to tone down the explanations for my students, 
obviously. But to do so, the teacher needs to have a very good grasp 
of the language so as not to make faulty reprensentations that would 
work small scale, but not later on when some students progress further 
in the language.
Maxim
19-Apr-2006
[244x2]
I find its hard to get people to "grasp" REBOL.  in the sense that 
they we all just see a different syntax twist at first.
The single most helpfull sweeping statement for me was "code IS data"
denismx
19-Apr-2006
[246x5]
The document "Rebol Essentials" starts with an explanation of value, 
word and block. Seems to be a good starting point. Haven't looked 
at how it introduces the syntax of system words later on. That is 
a crucial part. I want to find a subset of the 400 Rebol words that 
sould and can be learned first, giving the beginner a useful and 
powerful subset of instructions to start programming significant 
small apps.
Yes Maxim. But that is to mystical for teaching purposes.
Actually, since Von Neuman, code is treated as data. You load it 
into memory and process is as a special kind of data.
... so it's a long time ago that this concept is around.
I remember writing a program in Pascal that modified itself either 
in memory or rewriting itself on disk with variations.
Maxim
19-Apr-2006
[251x2]
not exactly what I meant.
there is no "code" in rebol.
JaimeVargas
19-Apr-2006
[253x2]
Maxim thats not completely true. What you want to say is that you 
can manipulate code as it was data at  runtime, and the modifications 
will affect the program next time there is an eval.
eval are trigger by function evaluation, do, reduce, parens and few 
others.
Maxim
19-Apr-2006
[255]
damn... I'd like to continue here... but I must run off  :-(
denismx
19-Apr-2006
[256x2]
In fact, in any programming language, code is just data that is executable. 
Some languages allow that the code-data be processed as any other 
date. Rebol is not the only one. And I do not believe that this is 
it's main characteristic. The fundamental characteristic of Rebol 
is that it is a language for exchanging data over networks, be it 
information (data) or programs (code) so that is can be used and 
executed (if code is passed) on any computer connected to the network.
For this to be possible, the language needs to be able to interpret 
new code passed to it, naturally.
JaimeVargas
19-Apr-2006
[258]
Yes denismx, but that is not the only approach possible. Erlang passes 
byte code, and it is very good at distributed computing, same with 
Termite.
denismx
19-Apr-2006
[259x2]
What is amazing is that the interpreter is so small and yet permits 
so much.
Of course...
JaimeVargas
19-Apr-2006
[261]
It has to do with the careful mapping of datatypes to literals.
denismx
19-Apr-2006
[262]
The small footprint, u mean?
JaimeVargas
19-Apr-2006
[263]
That is a forte of Rebol, it avoids data prickling or serialization 
which it is require in other languages.
denismx
19-Apr-2006
[264]
ic
JaimeVargas
19-Apr-2006
[265x2]
Regarding small footprint I think this is just proper coding, and 
avoidance of bloat.
mzscheme interpreter is only 300K in my system. So it is not unheard 
off.
denismx
19-Apr-2006
[267x3]
I'm sure there is a lot of that. But then again, 256K for the core 
seems very small.
ic
and Basic was pretty small too. Guess I'm getting to used to bloated 
stuff with the years :-)
JaimeVargas
19-Apr-2006
[270x4]
Yes.
Most interpreter machines are small. What makes the big is all the 
libraries and IDEs that they add to them.
Going home now. Keep enjoing rebol.
Before I go this is the shortest intro to scheme and functional programming 
that I had found. It will get you up to speed in this model in one 
day http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html
denismx
19-Apr-2006
[274]
I will look into it Jaime. Tks. Although I am doubtfull my solution 
to devising a "better" way to teach Rebol is in getting a better 
mastery of functional programming, I may be wrong. So I'll follow 
your lead.
JaimeVargas
20-Apr-2006
[275]
Functional programming demystifies a lot imho.
denismx
21-Apr-2006
[276x2]
I'm sure it does, but my impression is that I don't have any problem 
with that concept. I programmed in Logo and Prolog (for teaching 
purposes, not commercialy). The idea that I can build Rebol statements 
in blocks and evaluate them, all at runtime, does not phase me. But 
I'm always willing to learn more of anything. It never hurts (much).
The question I am asking myself now, in my exploration of Rebol, 
is: What is the smallest subset of predefined Rebol words that will 
empower a student to build significant small applications.