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

[REBOL] Re: set

From: larry:ecotope at: 15-Mar-2001 15:19

Hi Ryan Here is a short answer, others may wish to expand. When issued in the global context, both methods give the same results. But within the block defining an object, they do not:
>> ob: make object! [ f1: func [x][x * x] set 'f2 func [x][x + x]] >> probe ob
make object! [ f1: func [x][x * x] ] ; notice that only f1 is defined within the object, f2 is global
>> f2 4
== 8
>> ob/f1 4
== 16
>>
Using a setword causes the function to be defined within the object. Using the 'set function does not, instead, the word naming the function will be defined in the first ancestor context where it has already been defined, or if the word is previously undefined, in the global context. This behavior of 'set is actually very useful for exporting functions from objects, while in the func definition all of the object vars are available to it. HTH -Larry