[Python-Dev] Re: Extended Function syntax

Gerald S. Williams gsw@agere.com
Mon, 27 Jan 2003 09:57:21 -0500


Manuel Garcia wrote:
>     def _junk():
>         a = long_expression01(x0, y0)
>         b = long_expression02(x1, y1)
>         c = long_expression03(x2, y2)
>         return min(a,b,c), max(a,b,c)
>     d, e = _junk()
>     del _junk()
> 
> with the purpose being keeping a,b,c out of our nice clean namespace.

Don't you mean _junk? a,b,c are locals.

I suppose you could do something like this (though it
may seem a bit perverse here):

    def d():
        a = long_expression01(x0, y0)
        b = long_expression02(x1, y1)
        c = long_expression03(x2, y2)
        return min(a,b,c), max(a,b,c)
    d, e = d()

>     j = block:
>         def _get_j(self): return self._j
>         def _set_j(self, j): self._j = j
>         return property(_get_j, _set_j, None, 'dynamite!')

This doesn't seem quite as bad to me, though (YMMV):

    def j():
        def _get_j(self): return self._j
        def _set_j(self, j): self._j = j
        return property(_get_j, _set_j, None, 'dynamite!')
    j = j()

Not that I have any issues with your suggestion. I
especially like the fact it can be used to implement
"real" lambdas.

-Jerry