Refining functions.
[1/1] from: bhandley::zip::com::au at: 23-Aug-2000 13:32
I've finally got paths working on functions. So you can call a refined
function fairly easily. Other may know this, but it was new on me.
In the following example f1 will called a refined version of f2. The nice
thing is how it just calls existing functions. Also, it leaves the argument
passing to the caller.
to-refined-function: function [
"Refines a function with the specified refinements."
'f
refinements [any-block!]
] [p] [
p: to-path head insert/only head copy refinements f
:p
]
f1: function [
x y
] [a-func refines] [
refines: [r2 r3]
a-func: to-refined-function f2 refines
a-func x y
]
f2: func [
x
/r1
/r2 y
/r3
] [
print ["Function f2 was called with parameter" mold x]
if r1 [ print "Refinement r1 was called." ]
if r2 [ print ["Refinement r2 was called with parameter" mold y] ]
if r3 [ print "Refinement r3 was called." ]
]
Now the test.
>> f1 "test" "2nd-param"
Function f2 was called with parameter "test"
Refinement r2 was called with parameter "2nd-param"
Refinement r3 was called.
Brett.
--
>> my-rebol-stuff
== http://www.zipworld.com.au/~bhandley/rebol