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

World: r3wp

[Rebol School] Rebol School

Geomol
8-Feb-2009
[1596]
A block is a series of elements (inside [ and ]).
kib2
8-Feb-2009
[1597]
Geomol: ok, but is there any difference between all these terms ?
Geomol
8-Feb-2009
[1598]
Try in the REBOL console:

>> ? datatype!
Henrik
8-Feb-2009
[1599]
you can ask whether a datatype is a series with 'series?.
kib2
8-Feb-2009
[1600]
So what's the difference between a block and a serie ? A serie is 
a block for me no ? (the inverse may not be right)
Henrik
8-Feb-2009
[1601]
not all series are alike. We tend to differ between strings and blocks 
and blocks come in a few different types, optimized for specific 
use, but they may hold the same content.
Geomol
8-Feb-2009
[1602]
A computer language theorist might tell you differences between arrays, 
lists and series. I suggest, you take the practical view and look 
at what datatypes, you find in REBOL.
Henrik
8-Feb-2009
[1603]
kib2, let REBOL decide what is what, by asking the datatype:

>> series? [a b c]
== true
>> series? "abc"
== true


You can do that, because REBOL has so many different datatypes, allowing 
you to be precise in your expression.
Geomol
8-Feb-2009
[1604]
>> series? "abc"
== true
>> series? []
== true
>> series? make list! 10
== true

So there are many kinds of series.
kib2
8-Feb-2009
[1605]
Geomol: Rebol is the langage where I've found the more datatypes 
!
Geomol
8-Feb-2009
[1606x2]
hehe :-)
kib, me too.
Henrik
8-Feb-2009
[1608]
if we didn't have this many datatypes (R3 has even more), parsing 
and dialects would be less fun.
Geomol
8-Feb-2009
[1609]
kib, you'll see, the number of datatypes is one of the really really 
huge forces of rebol.
kib2
8-Feb-2009
[1610x2]
email!, url!, money! etc. That's good when you parse something
Henrik: R3 adds other datatypes ? like ?
Henrik
8-Feb-2009
[1612]
yeah, email! is actually an exception. it doesn't work very well. 
you will find that a few types can't be serialized properly, which 
means an email! can't be recognized. but it works for the majority 
of types.
Geomol
8-Feb-2009
[1613]
Or when you use functions:
read %disk-file
read http://www.rebol.com
(or reading some other port)
Henrik
8-Feb-2009
[1614x2]
kib2, percent!, task!, vector!, gob!, handle!, closure!. There are 
more.
plus in R3 you can define your own and group types in new ways.
kib2
8-Feb-2009
[1616]
really impressive
Henrik
8-Feb-2009
[1617x2]
using typesets, you can say something like:

>> image-type: make typeset! [binary! image! url!]
== make typeset! [binary! image! url!]

(doesn't make that much sense, but you get the idea.)
(that's also R3 only)
Geomol
8-Feb-2009
[1619]
Henrik, is there an example of a user defined datatype in R3 somewhere?
Janko
8-Feb-2009
[1620]
wow, you can make your own and combine.. that seems very good!
Henrik
8-Feb-2009
[1621]
kib2, using MOLD/ALL, you can study serialization, on how to build 
serialized blocks of data.
kib2
8-Feb-2009
[1622]
cool and powerful, but we've to wait until R3 gets more stable.
Henrik
8-Feb-2009
[1623x2]
Geomol, try: ? typeset!

Some interesting ones turn up.
actually only one at this point (scalar!), but I think there will 
be more, if it makes sense to have them.
kib2
8-Feb-2009
[1625]
Henrik: :)
Geomol
8-Feb-2009
[1626]
kib, you had other questions from reading the book?
Janko
8-Feb-2009
[1627]
Will R3 also have something like multiple dispatch then?
Henrik
8-Feb-2009
[1628]
explain? (I'm not good with terms)
kib2
8-Feb-2009
[1629]
Geomol: yes, it's more practical : do you often use globals ?
Geomol
8-Feb-2009
[1630x2]
No, I try not to. It's nice to have kind of globals in a long script, 
to easily share values between functions, but then I put the whole 
thing within a context block, like:

context [

... all my code go here ...

]	; end of context
That way my "globals" isn't really globals, they're local to my context.
Janko
8-Feb-2009
[1632]
Henrik: I am not very good either :) ..  I will try to find an example
Henrik
8-Feb-2009
[1633]
Geomol, the reason you do that, is of course to avoid garbage collection 
of said "locals"?
Geomol
8-Feb-2009
[1634]
CONTEXT is a function, and you can see, what it does with:

>> source context
kib2
8-Feb-2009
[1635]
context is used for that purpose ?
Henrik
8-Feb-2009
[1636]
context is just another word for "make object!"
kib2
8-Feb-2009
[1637]
ah ok.
Henrik
8-Feb-2009
[1638]
and objects are contexts. when wrapping set-word!s in contexts, they 
stay inside that context.
Geomol
8-Feb-2009
[1639]
Henrik, no, not really because of garbage collection, because the 
garbage collector doesn't collect words defined 'globally', right? 
I do it, because it's good programming practise to not have many 
globals. :-)
kib2
8-Feb-2009
[1640]
Henrik: that' seems a good way to handle namespaces ?
Henrik
8-Feb-2009
[1641x2]
kib2, you'll find that many scripts come wrapped in contexts. this 
is the best we can do until R3 brings us modules. contexts are not 
waterproof, though.
context [
  a: 1 ; only inside context
  set 'b 2 ; global
]


This can be useful, if you want to create an object with one "public" 
function.
Janko
8-Feb-2009
[1643]
>> 3 + 2  == 5
>> 3x2 + 2x3 == 5x5
Henrik
8-Feb-2009
[1644x2]
Geomol, true. In some extreme cases however, I've experienced crashes, 
because too much garbage collection happens. I always had to solve 
it by converting some locals to globals.
kib2, since you can bind contexts everywhere, even inside other contexts, 
they are not really secure and so you can't make things really private 
to a context. Modules will do that, I believe.