[REBOL] faq
From: rebol665:ifrance at: 19-Jan-2002 12:47
Hi Rebollers
Another FAQ from the time where I was asking myself and the Rebollers "Is
Rebol suited for Object Oriented programming ?" and got no response :(
<faq>
How to pass function as argument?
Short answer:
Using 'get
Problem illustration:
An object function must be set to an outside function.
obj: make object! [
name: "obj"
obj-func: none
]
fn1: does [print "Hello Rebollers"]
fn2: func [ f [function!]
][
print "My task is to affect obj/obj-func with fn1"
obj/obj-func: f
]
>> fn2 fn1
Hello Rebollers
** Script Error: fn2 expected f argument of type: function
** Where: do-boot
** Near: fn2 fn1
>>
Problem resolution
Get must be used twice: (1) in the fn2 definition. (2) in the fn2 call.
fn2: func [ f [function!]
][
print "My task is to affect obj/obj-func with fn1"
obj/obj-func: get 'f
]
fn2 get 'fn1
My task is to affect obj/obj-func with fn1
obj/obj-func
Hello Rebollers
</faq>
Patrick