Function Inheritance
[1/2] from: lmecir::mbox::vol::cz at: 10-Mar-2003 16:09
Hi all,
me and Romano are helping Gabriele to do some type definition experiments in Rebol.
Gabriele wanted to have a "function inheritance" HOF like SUBFUNC or TSUBFUNC as follows:
>> tinsert: tsubfunc :insert load mold third :insert [print Inserting...
super]
>> head tinsert/only [] []
Inserting...
== [[]]
>> head tinsert [] [2]
Inserting...
== [2]
The only thing needed is to call SUPER without any arguments/refinements and the parent
obtains all the arguments and refinements automatically. The sources of the functions
are:
http://www.rebolforces.com/~ladislav/tfunc.r
and
http://www.rebolforces.com/~ladislav/subfunc.r
If you want to be able to use all argument handling methods (i.e. not just the normally
evaluated arguments), you can use FUNCALL5 and PREPARE-AR5 (which support even unevaluated/fetched
argument passing methods) instead of FUNCALL and PREPARE-AR, but it will be slower.
The same holds for SUBFUNC and TSUBFUNC. TSUBFUNC is more reliable (no problem with error
and set-word handling, etc.), but slower.
Cheers
-L
[2/2] from: greggirwin:mindspring at: 10-Mar-2003 10:40
Hi Ladislav,
Thanks to all you guys! I'm always amazed at the things you can make
REBOL do. Now I need some free time to check it out. :\
-- Gregg