Re: [Python-Dev] Extended Function syntax

Just van Rossum <just@letterror.com> writes:
Jim Fulton wrote:
In particular:
def name(arg, ...) [expr1, expr2, expr3]: ...body...
would be equivalent to (some variation on):
def name(arg, ...): ...body...
name=expr1(expr2(expr3(name)))
With Michael's patch (which indeed still works) it's actually
name = expr3(expr2(expr1(name)))
I can't remember if that was deliberate or accidental. I think deliberate.
I wonder if the same mechanism could be used in class statements. If I had this, I might say what interface a class implements with:
class foo(spam, eggs) [implements(IFoo, IBar)]: body of class
or (wo parens):
class foo [implements(IFoo, IBar)]: body of class
I don't know how Zope interfaces work, but I can imagine the following could be made to work as well:
class foo(spam, eggs) [IFoo, IBar]: body of class
I think this would be wonderful. Would someone be interested in extending Michael's patch to also cover the class statement?
Maybe even me :-) It wasn't very hard. http://starship.python.net/crew/mwh/hacks/meth-syntax-sugar-2.diff You still can't use lambdas in the filter list. I thought I'd fixed that ages ago, but it seems not. Cheers, M. -- I have no disaster recovery plan for black holes, I'm afraid. Also please be aware that if it one looks imminent I will be out rioting and setting fire to McDonalds (always wanted to do that) and probably not reading email anyway. -- Dan Barlow

In particular:
def name(arg, ...) [expr1, expr2, expr3]: ...body...
would be equivalent to (some variation on):
def name(arg, ...): ...body...
name=expr1(expr2(expr3(name)))
With Michael's patch (which indeed still works) it's actually
name = expr3(expr2(expr1(name)))
I can't remember if that was deliberate or accidental. I think deliberate.
It certainly surprises me less -- this is left-to-right (applying expr1 first) which is goodness. --Guido van Rossum (home page: http://www.python.org/~guido/)

Guido van Rossum wrote:
In particular:
def name(arg, ...) [expr1, expr2, expr3]: ...body...
would be equivalent to (some variation on):
def name(arg, ...): ...body...
name=expr1(expr2(expr3(name)))
With Michael's patch (which indeed still works) it's actually
name = expr3(expr2(expr1(name)))
I can't remember if that was deliberate or accidental. I think deliberate.
It certainly surprises me less -- this is left-to-right (applying expr1 first) which is goodness.
+1 I suppose the following would also be possible, provided that types(...) returns a callable, right ? def myfunc(x,y,z) [types(int, int, float), cacheglobals]: return math.sin(x*y/z) .... and cacheglobals would be able to rewrite the byte code too. Nice :-) -- Marc-Andre Lemburg CEO eGenix.com Software GmbH _______________________________________________________________________ eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/

Michael Hudson <mwh@python.net> writes:
You still can't use lambdas in the filter list. I thought I'd fixed that ages ago, but it seems not.
I have now, and of course the fix was totally trivial but still took a couple of hours to find. I'll just stop pretending I understand the compiler. http://starship.python.net/crew/mwh/hacks/meth-syntax-sugar-3.diff What's left? Ah ha, we now have PEP 306, which I need to tell python-dev about. Cheers, M. -- 93. When someone says "I want a programming language in which I need only say what I wish done," give him a lollipop. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html
participants (3)
-
Guido van Rossum
-
M.-A. Lemburg
-
Michael Hudson