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

 
______________________________________________________________________________
ifrance.com, l'email gratuit le plus complet de l'Internet !
vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP...
http://www.ifrance.com/_reloc/email.emailif


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to