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

[REBOL] Re: R: Re: Links ? Pointers ?

From: moliad:gm:ail at: 27-Aug-2009 22:00

there is one feature people often forget about rebol..... it has NO syntax. how do you represent/access a variable... hum... x: "some value" print x how do you represent an object.... hum... x: context [v: "some value"] print x how do you represent a function? ... hum x: func [][ "some value"] print x hum.... see any constant? however you define x... in any kind of data... you always USE it the same way... some types just have more accessors... like objects which have path access. now you realize that the function and the "variable" both print the same thing. just the string. this is your secret indirect reference weapon! you can always (almost) replace a value with a function and let the function do some "special trick" ;-) here, what you do is let the function point to some other value.... so if your code needed to do: a: b: "some value" you can ask function to act as a go between. the nice thing is that most of your code won't have to change because REBOL has so little syntax, only the assignment part will have to be updated... which is usually much more confined a task than access to a value everywhere in your app. functions create a context, and that context persists for each call.. so a function actually can store values, here we use a block without copying it at each eval... what some think is a limitation actually now is shown as the feature it is. :-) so let's say this is what your app should be: person: context [ uid: 666 name: "me" ] employee: context [ uid: user/uid title: "Workoholic" ] managers: [ ceo: employee/uid ] now as you know, changing the uid in person won't be reflected in employe or managers... so you're screwed! ---- Look at this modified version using function trick: person: context [ uid: func [/set value][data: [#[none]] either set [data/1: value][data/1]] name: "me" ] employee: context [ uid: get in person 'uid title: "Workoholic" ] managers: context [ ceo: get in employee 'uid ]
>> person/uid/set 222
== 222
>> managers/ceo
== 222
>>
this is one way to use the function hack, but there are many others, and they depend on the application itself. there are a few little details when using the hack, but usually, its pretty invisible. Hope this helps :-) -MAx