On Thu, Aug 6, 2009 at 19:00, Fernando Perez<fperez....@gmail.com> wrote: > On Thu, Aug 6, 2009 at 1:57 PM, Sturla Molden<stu...@molden.no> wrote: >> In order to reduce the effect of immutable arrays, we could introduce a >> context-manager. Inside the with statement, all arrays would be >> immutable. Second, the __exit__ method could trigger the code generator >> and do all the evaluation. So we would get something like this: >> >> # normal numpy here >> >> with numpy.accelerator(): >> >> # arrays become immutable >> # lazy evaluation >> >> # code generation and evaluation on exit >> >> # normal numpy continues here >> >> >> Thus, here is my plan: >> >> 1. a special context-manager class >> 2. immutable arrays inside with statement >> 3. lazy evaluation: expressions build up a parse tree >> 4. dynamic code generation >> 5. evaluation on exit > > You will face one issue here: unless you raise a special exception > inside the with block, the python interpreter will unconditionally > execute that code without your control. I had a long talk about this > with Alex Martelli last year at scipy, where I pitched the idea of > allowing context managers to have an optional third method, > __execute__, which would get the code block in the with statement for > execution. He was fairly pessimistic about the possibility of this > making its way into python, mostly (if I recall correctly) because of > scoping issues: the with statement does not introduce a new scope, so > you'd need to pass to this method the code plus the locals/globals of > the entire enclosing scope, which felt messy.
Sometimes, I fantasize about writing a python4ply grammar that repurposes the `` quotes to provide expression literals and ``` ``` triple quotes for multiline statement literals. They would be literals for _ast abstract syntax trees. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion