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

World: r3wp

[Rebol School] Rebol School

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.
Geomol
8-Feb-2009
[1646]
Henrik, ok got it. Well, in huge programs (like RPaint), I try to 
avoid garbage collection as much as possible. Garbage collection 
always works against performance, so it's bad in real-time applications 
(multi-media, games, etc.).
Janko
8-Feb-2009
[1647]
+ in this two cases "dispatches" on the type of arg... but this is 
probably handlede inside + , so if you define new type (vector3d) 
you couldn't make + work for that datatype too without changing it 
... in multiple dispatch + is a generic word and you add definitions 
for it for that datatype so it can work on them without changing 
or having access the original +  (basically similar to what is operator 
overloading at static lang, here it dispatches in runtime based on 
type)
Henrik
8-Feb-2009
[1648x2]
Janko, I think you would solve that with typesets.
OTOH, maybe not. the function itself must support whatever argument 
is passed to it.
kib2
8-Feb-2009
[1650]
Is there any quickref card for Rebol somewhere ?
Henrik
8-Feb-2009
[1651]
kib2: The word browser is pretty good. It's inside the Viewtop under 
REBOL/Tools, I think.
kib2
8-Feb-2009
[1652]
ok thanks!
Geomol
8-Feb-2009
[1653x2]
Janko, I've been thinking about this problem too, and I'm not sure, 
what's best. Is it good enough, what we can do with functions today? 
Like:

>> old-add: :add

>> add: func [a b] [either string! = type? a [join a b] [old-add 
a b]]
>> add 4 5
== 9
>> add "Hi " "John"
== "Hi John"

Now ADD can also be used to join strings.
kib, I often use the REBOL dictionary: http://www.rebol.com/docs/dictionary.html
kib2
8-Feb-2009
[1655]
Geomol: that's exactly what I was looking for!
Janko
8-Feb-2009
[1656x3]
fictional example I made up:
make-type dog!
make-type cat!

make-generic 'say

say: func [ a [ dog! ]] [ "woof" ]
say: func [ a [ cat! ]] [ "meov" ]
or no.. say: woulnd't be good .. something like
Geomol
8-Feb-2009
[1659]
Janko, yes, that would be cool to do.
Janko
8-Feb-2009
[1660]
make-type dog!
make-type cat!

make-generic 'say [ a [ dog! ]] [ "woof" ]
make-generic 'say [ a [ cat! ]] [ "meov" ]
Henrik
8-Feb-2009
[1661]
kib2, note: the web based dictionary is older and less updated than 
the word browser, but it works OK.