Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

object method binding

 [1/4] from: media::quazart::com at: 8-Nov-2001 9:52


Hello world, a question for context/binding experts how do I re-define a method'd function so that it uses a variable defined in the original function but which does not access data within the object itself, and which its binding is unknown? for example: I know of the existence of the following object: weird: make object! [ weird-func: func [][ print external-variable ] ] the problems is: ---------------- Because the code was built within a dynamic loop, at the time of creation, external-variable WAS defined so rebol linked (or bound?) that word to whatever it meant at that time. but as you see, it does not reference a value within weird itself but rather a value that it linked outside of weird, so somehow its still valid, but we do not know exactly what external-variable "points" to... Now the question: -------------------- how can I replace the weird method to another function but still use the original's external-variable value... like if I wanted to do my-extension: "ext" extended-weird: func[][ print ["I have extended" external-variable my-extension] ] weird/func: :extended-weird ... of course the above WILL fail ... in the context of this problem, there is simply no way to trap the original definition of weird, so that I can create a global to re-assign external-value in my own function... ain't context and binding fun!!? Thanks in advance! -Maxim

 [2/4] from: rotenca:telvia:it at: 8-Nov-2001 18:03


Hi, Media
> weird: make object! [ > weird-func: func [][
<<quoted lines omitted: 19>>
> ] > weird/func: :extended-weird
The second of a function is the real body of the function, with all its binds. you must search in it, copy it and so on. Example: external-variable: 1 weird: make object! [ weird-func: func [][ print external-variable ] ] use [external-variable][ do second get in weird 'weird-func ] --- Ciao Romano

 [3/4] from: g:santilli:tiscalinet:it at: 9-Nov-2001 11:31


Media wrote:
> weird: make object! [ > weird-func: func [][ > print external-variable > ] > ]
I don't know if I understand correctly, but maybe this can help:
>> use [external] [
[ external: "I am the one" [ f: func [a] [print [a "-" external]] [ ]
>> f 3
3 - I am the one
>> external
** Script Error: external has no value ** Near: external Now if we want to create a function G that works like F...
>> external-word: third second second :f
== external
>> get external-word
== "I am the one"
>> g: func [a] compose/deep [print [a "-" (external-word)]] >> g 3
3 - I am the one
>> source g
g: func [a][print [a "-" external]] HTH, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [4/4] from: media:quazart at: 9-Nov-2001 13:35


at first glance this looks EXACTLY like what I need... I'll test it within objects to see if it works... thanks! -MAxim

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted