> On Mar 30, 2015, at 11:01, Werner Kassens <wkass...@libello.com> wrote:
> 
>  i had a little program, that constructs an array of blocks (no object 
> methods) via opal from scratch (using strings). now this worked of course 
> without problems, but there are situations where it would be nice if those 
> blocks would have - in a _simple_ way - access to common variables 
> constructed by the program, iow if all those blocks would live in the same 
> 'space' as those variables - or however thats called correctly. does this 
> scenario apply as a possible use case (obviously completely different from 
> Johan's use case) ?

Werner, let me surprise you: what I am doing is in the end exactly that! :-)

I am compiling blocks, written by the user of the system, that need references 
to variables that are outside the block, and they are shared between the 
different blocks. (The blocks have been written in a plain text textfield). So 
how do I have them access the variables?

 Here is the setup:
- I generate a class (MyGeneratedClass) with as *class variables* all the 
variables that need to be accessed by the different blocks
- For each block I generate a string with method source code 
(myGeneratedMethod_timestamp), whose body is: return the block 
- I compile the method and add it to MyGeneratedClass class (add it at class 
side)
- I execute each method (MyGeneratedClass myGeneratedMethod_timestamp) , which 
gives me a BlockContext that has captured the variables.
- sending value to that executes the block, and all blocks share the variables 
in MyGeneratedClass.

Simple :-)

And thanks to Marcus for discussing this with me a couple of years ago ...

---> Save our in-boxes! http://emailcharter.org <---

Johan Fabry   -   http://pleiad.cl/~jfabry
PLEIAD lab  -  Computer Science Department (DCC)  -  University of Chile


Reply via email to