[Python-Dev] Extended Function syntax

Andrew McGregor andrew@indranet.co.nz
Sun, 02 Feb 2003 15:47:02 +1300


--==========1714979620==========
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline



--On Sunday, February 02, 2003 10:56:29 +1300 Andrew McGregor=20
<andrew@indranet.co.nz> wrote:

> Then:
>
> defmacro property(name, docstring, @get, @set, @delete):
>     def getter interpolate(get.arglist):
>         interpolate(get.block)
>     def setter interpolate(set.arglist):
>         interpolate(set.block)
>     def deleter interpolate(delete.arglist):
>         interpolate(delete.block)
>     return:
>         name =3D property(docstring, getter, setter, deleter)
>
> class Circle(object):
>    property circumference, """Circumference of the circle""":
>        get (self):
>            return self.radius*6.283
>        set (self, value):
>            self.radius =3D value/6.283
>        delete (self):
>            del self.radius
>
> would do the obvious thing using block keyword arguments (I can't think
> how to express the anonymous scope implied here in regular Python; the
> intention is that getter and friends are defined in the local namespace
> of the macro invocation).
>
> Of course the proposed syntax is hypothetical, but I think it's quite
> clean.

Hmmm, maybe that should have been:

defmacro property(name, docstring, @block):
    block()
    return:
        name =3D property(docstring, get, set, delete)

class Circle(object):
   property(circumference, """Circumference of the circle"""):
       def get(self):
           return self.radius*6.283
       def set(self, value):
           self.radius =3D value/6.283
       def delete(self):
           del self.radius

I still think block keyword arguments would be nice, but this can be done=20
without them.

Andrew
--==========1714979620==========
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+PIamHamGxvX4LwIRAjRXAKDOTgODINE1C6mxdLRb5qAeJf1w1ACg5AHZ
OxiObNlVxp8SXUnOIb35AOE=
=mjDP
-----END PGP SIGNATURE-----

--==========1714979620==========--