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

[REBOL] Words, Bindings and Contexts. (9)

From: lmecir:geocities at: 29-Jul-2000 17:01

; Model of Use behaviour: ; *********************** sim-use: func [ "Defines words local to a block." words [block! word!] "Local word(s) to the block" body [block!] "Block to evaluate" /local context ] [ if word? words [words: reduce [words]] ; create the Context context: make-context words do bind body in context 'self ] { The described behaviour has got its drawbacks (See Bug in Use?). There is a possibility to improve the behaviour, see the next model: } r-use: func [ "Defines words local to a block." words [block! word!] "Local word(s) to the block" body [block!] "Block to evaluate" /local context ] [ if word? words [words: reduce [words]] ; create the Context context: make-context words do bind/copy body in context 'self ] { The last subject left is the behaviour of make object!. Here it is: } make-object!: func [ {make object! simulation} spec [block!] /local words result ] [ words: make block! 0 foreach elem spec [ if set-word? get/any 'elem [ append words to word! elem ] ] result: make-context words result/self: result do bind spec in result 'self return get/any in result 'self ] { Analogically as above, this code is not well-behaved in some circumstances. I would prefer the following: } r-make-object!: func [ {make object! simulation} spec [block!] /local words result ] [ words: make block! 0 foreach elem spec [ if set-word? get/any 'elem [ append words to word! elem ] ] result: make-context words result/self: result do bind/copy spec in result 'self result ]