Code blocks

Simon Burton simonb at webone.com.au
Mon Oct 13 20:15:19 EDT 2003


On Mon, 13 Oct 2003 16:31:27 -0400, David Mertz wrote:

...
> So for that, I would suggest a new scopeless pseudo-function syntax.
> E.g.:
> 
>     block foo(this, that, other):
>         x = this+that
>         y = this*other
>         z = x // (y-that)
> 
> Using this is like a function, but the names wind up in the calling
> namespace:
> 
>     def bar(someblock):
>         a, b, c = (4, 5, 6)
>         someblock(a,b,c)
>         return x,y,z
> 
>     vals = bar(foo)   #-> (9, 24, 0)
> 
> That is, I have no desire for blocks to be nameless, just for them to be
> passable as first class objects.
> 
> Yours, David...

Yeah, right on!
I often hack code realtime, and wish i could name a chunk of code
without having to return/accept huge (and often changing) tuples of stuff...

Anyway, now that i think about this, it should be possible to lookup
the calling context's locals and insert the current locals. Then
wrap this in a function, "expose", say. One could even do this with
the arguments and write an "absorb" function:


     def foo():
         absorb()
         x = this+that
         y = this*other
         z = x // (y-that)
         expose()

Then maybe later on when the code has cooled down sufficiently, one could
revert to the more informative args/return mechanics.

Simon.






More information about the Python-list mailing list