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

[REBOL] Re: Competition - There must be a better way to .....

From: ale870::gmail::com at: 25-Nov-2007 9:55

Now I don't remember the function, but in Rebol you can dynamically get the variables used in one function. It means you could create a bind at runtime using such variables.. The problem is in this way you cannot make difference between locals and globals. Can you establish a "standard" and, for example, expect that the new dynamic context may contain a default function (e.g.: called (binder) ) to be called to get/set bind variables? This is the way that in languages like java use with "interface" or abstract classes (like a "promise": you simply say that the new context must contain a specific function(s) ). On Nov 25, 2007 1:45 AM, Peter Wood <pwawood-gmail.com> wrote:
> Alessandro > > I think the problem that you've solved is slightly different to mine. I > need to add words to the context after it has been created as I don't > know what variables will be supplied until the script is running. > > Regards > > Peter > > On Saturday, November 24, 2007, at 10:55 pm, Alessandro Manotti wrote: > > > I had the same problem (similar problem) when I created Framework > > "Laccio". > > I solved simply creating a variabile in the external container: > > > > internal-variable: none > > > > ctx1: context [ > > internal-variable: "A" > > ] > > > > I used this "trick" to create several instances of the same Layout > > (View > > Layout). See the following real example: > > > > ctx1: context [ > > myButton: none > > > > myLayout: [ > > myButton: button "Click me" > > ] > > ] > > > > view layout ctx1/myLayout > > > > > > > > If you think I'm to the right way, you can donwload my framework from > > http://laccio.wordpress.com then take a look to the viewer > > implementation > > (not the controller). > > > > > > > > > > > > > > On Nov 24, 2007 5:13 AM, Peter Wood <pwawood-gmail.com> wrote: > > > >> > >> Seeing the great response to previous competitions, I thought that I'd > >> start one too. > >> > >> As part of a test framework I'm working on, I want to evaluate the > >> test > >> code in a separate context to avoid clashes between the code being > >> tested and the test framework code. > >> > >> I found it wasn't as easy as simply binding the block to a different > >> context. I've come up with a method based on adding new words in the > >> code to be evaluated to the context before binding them. It seems to > >> work (I haven't tested it extensively yet) but it's complicated and > >> uses recursion. > >> > >> I'm sure many of you can come up with simpler and non-recursive > >> solutions? > >> > >> My code: > >> > >> eval-ctx: make object! [ > >> anchor: none > >> eval: function [code-block [block!]] [ > >> result > >> ][ > >> bind code-block 'anchor > >> if error? set/any 'result try code-block [ > >> result: disarm result > >> ] > >> result > >> ] > >> ] > >> > >> > >> evaluate: function [code-block [block!]] [ > >> words-to-add > >> find-words-to-add > >> p > >> w > >> ][ > >> words-to-add: copy [] > >> find-words-to-add: func [code-block [block!]][ > >> parse code-block [ > >> any [ > >> set w block! ( > >> find-words-to-add w ;; recursive call > >> ) > >> | > >> set w set-word! ( > >> if not in eval-ctx to word! w [ > >> insert insert words-to-add reduce w none > >> ] > >> ) > >> | > >> 'set set w lit-word! ( > >> if not in eval-ctx w [ > >> insert insert words-to-add to set-word! w none > >> ] > >> ) > >> | > >> set p path! set w lit-word! ( > >> if 'set = first p [ > >> if not in eval-ctx w [ > >> insert insert words-to-add to set-word! w none > >> ] > >> ] > >> ) > >> | > >> skip > >> ] > >> ] > >> ] > >> find-words-to-add code-block > >> if words-to-add <> [] [ > >> eval-ctx: make eval-ctx words-to-add > >> ] > >> eval-ctx/eval code-block > >> ] > >> > >> A sample: > >> > >>>> evaluate [test1: "peter"] > >> [test1: "peter"] > >> == "peter" > >>>> test1 > >> ** Script Error: test1 has no value > >> ** Near: test1 > >>>> probe eval-ctx > >> make object! [ > >> anchor: none > >> eval: func [code-block [block!] /local > >> result > >> ][ > >> bind code-block 'anchor > >> if error? set/any 'result try code-block [ > >> result: disarm result > >> ] > >> result > >> ] > >> test1: "peter" > >> ] > >> > >> Regards > >> > >> Peter > >> > >> -- > >> To unsubscribe from the list, just send an email to > >> lists at rebol.com with unsubscribe as the subject. > >> > >> > > > > > > -- > > > > //Alessandro > > > > http://sguish.wordpress.com > > http://laccio.wordpress.com > > > > > > -- > > To unsubscribe from the list, just send an email to > > lists at rebol.com with unsubscribe as the subject. > > > > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject. >
-- //Alessandro http://sguish.wordpress.com http://laccio.wordpress.com