what to do with bind ?/an example
[1/2] from: tim::johnsons-web::com at: 25-Nov-2001 17:54
Here's a REALLY simple illustration of what 'bind can do.
<wink>It took something this simple for me to understand it</wink>
REBOL[]
x: "five"
obj: make object! [x: 5
modify: func[arg[block!]][do bind arg 'self]
]
print join "This is x outside of the object: " x
print join "This is x inside of the object: " obj/x
print {now let's use obj/modify which is "bound" to "obj"}
obj/modify [x: 10]
print join "This is x outside of the object: " x
print join "This is x inside of the object: " obj/x
produces:
This is x outside of the object: five
This is x inside of the object: 5
now let's use obj/modify which is "bound" to "obj"
This is x outside of the object: five
This is x inside of the object: 10
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com
[2/2] from: rebol665:ifrance at: 26-Nov-2001 13:07
Hi,
Thank you Tim. Your program is simple enough to make me get it. I have added
a new object function, without the binding. As expected the X outside the
object was modified.
I'am very grateful to the rebol-list and my skills improves step by step.
REBOL[]
x: "five"
obj: make object! [
x: 5
modify: func[arg[block!]][do bind arg 'self]
new-modify: func[arg[block!]][do arg ]
]
print join "This is x outside of the object: " x
print join "This is x inside of the object: " obj/x
print {now let's use obj/modify which is "bound" to "obj"}
obj/modify [x: 10]
print join "This is x outside of the object: " x
print join "This is x inside of the object: " obj/x
print {now let's use obj/new-modify without binding}
obj/new-modify [x: 15]
print join "This is x outside of the object: " x
print join "This is x inside of the object: " obj/x
halt
produces:
This is x outside of the object: five
This is x inside of the object: 5
now let's use obj/modify which is "bound" to "obj"
This is x outside of the object: five
This is x inside of the object: 10
now let's use obj/new-modify without binding
This is x outside of the object: 15
This is x inside of the object: 10