[Python-Dev] syntactic sugar idea for {static,class}methods
Michael Hudson
mwh@python.net
13 Feb 2002 10:41:13 +0000
barry@zope.com (Barry A. Warsaw) writes:
> >>>>> "MH" == Michael Hudson <mwh@python.net> writes:
>
> MH> Some time ago, Gareth McCaughan suggested a syntax for
> MH> staticmethods. You'd write
>
> MH> class C(object):
> | def static(arg) [staticmethod]:
> | return 1 + arg
>
> | C.static(2)
> | => 3
>
> Very interesting! Why the square brackets though? Is that just for
> visual offset or is there a grammar constraint that requires them?
Um, no big reason; they were what Gareth suggested, so I implemented
that. He may have got the idea from the slides from one of Guido's
presentations -- it was reading them that reminded me I'd done this
and wanted to mention it here.
Note, though, that my patch allows an arbitrary number of
*expressions* in the square brackets; in principle you can do things
like:
>>> def h() [apply, (lambda f:(lambda : f() + 1))]:
... return 1
...
and have `h' be 2 (except that this caused an abort at the moment -- I
must have missed something in my symtable code).
Not sure whether this is a good idea, of course, but allowing
arbitrary expressions does actually make the compiling easier.
Allowing arbitrary expressions without delimiters sounds like a bad
idea, both for parsers and people.
> I'd leave them out of the picture, unless you mean to imply that a
> list is acceptable in that position <wink>.
Well, it is, at the moment...
Cheers,
M.
--
: exploding like a turd
Never had that happen to me, I have to admit. They do that
often in your world? -- Eric The Read & Dave Brown, asr