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

[REBOL] Re: Pointers, Context in Rebol 3.0 (For the real Rebol Lovers)

From: anton::wilddsl::net::au at: 24-Mar-2007 12:01

You can change the body code of the function
> a1: func [a b] [a / b] > > inst1: make template [f1: :a1] > inst2: make template [f1: :a1] > > I expect that both inst1 and inst2 share the same "pointer to a1"
a1 and f1 in each instance refer to the same function, yes.
> Performing a: > > a1: func [a b] [a / b + 1] > > should change both INST1/f1 and INST2/f1 because they should point to the > same function as I have declared [F1: :A1]. Instead only a1 is changed > because a1 is copied during object creation and not pointed.
You could do this: inst1: make template [] set in inst1 'f1 :a1 inst2: make template [] set in inst2 'f1 :a1 Another way is to put functions in a sub-object, just like face/feel. eg: template: context [ aaa: 1 funcs: context [f1: none f2: none] ] a1: func [a b] [a / b + 1] template/funcs/f1: :a1 inst1: make template [] inst2: make template [] inst1/funcs/f1 3 4 inst2/funcs/f1 3 4 These are a little bit uncomfortable. I think automatic copying in MAKE was a mistake. MAKE previously shared functions (ie. did not copy them). At the time of the discussion, people were confused about how VID worked and shared/copied its facets. I didn't have a strong opinion then because I wasn't sure myself, but these days I have a strong opinion of copying. --- AVOID it, because you can't "uncopy" afterwards. Regards, Anton.