REBOL [
Title: "Andrew, you beast!"
File: %test3.r
]
rf: func [
][
do %test3.r
]
O: make object! [
f1: func [] [print "F1."]
f2: func [] [print "F2."]
set 'Dialect func [blk [block!]] [reduce bind blk 'f1]
print
{
Amazingly, you can put any code in the object and the darn stuff
will just get executed when the object is creation code is executed.
Otherwise you wouldn't be seeing this message now.
Of course when you create an object by simple cloning
of another object you probably don't get this
execution side-effect.
Notice how Andrew had previously named blk
as Dialect, which was certainly confusing
but as far as I could tell didn't add to
the understanding.
However, he has to use "set 'Dialect"
instead of simply having "Dialect:"
because he doesn't want Dialect hanging
around as another element (method) of the object,
but in fact wants Dialect to be a global critter
accessible outside the object later.
Notice that because
F1 and F2 are functions they will be
automatically executed when they are reduced.
What all this has to do with dialects exactly is
still abit unclear. I suppose it means you
can bind a block to another block or word
and it will share the context of that other
block. I wonder what would happen if you
unset O at this point. Could you still
run Dialect and have it bind and reduce another block
to what O was bound to?
}
]
;-------------- just a side-track
OO: make O [] ;-- notice you dont see all that text repeated again now.
unset 'OO ;-- just to keep it from being a distraction
;-------------- the main enchilada (anyone hungry?)
B: [f1 f2 f1]
Dialect B
print "-----"
;------------------ more derring do
unset 'O
C: [f1 f2 f2 f1]
Dialect C ;-- that ol' abracadabra still has some magic left in it.
halt