On Mon, 2011-03-07 at 19:50 -0800, Raymond Hettinger wrote:
> On Mar 7, 2011, at 4:56 PM, Larry Hastings wrote:
>> >
> > On 03/03/2011 03:45 PM, Greg Ewing wrote:
> >> I think we should have assignment decorators.
> >>
> >> @decorator
> >> lhs = rhs
> >>
> >> would be equivalent to
> >>
> >> lhs = decorator('lhs', rhs)
> >>
> >
> > I timidly propose an alternate syntax. What I don't like about the above proposal: assignment is no longer a one-liner. So let's try it inline.
> >
> > Example 1:
> >
> > lhs = @decorator
> >
> > is equivalent to
> >
> > lhs = decorator(classobject, 'lhs', None)
> >
> . . .
> >
> > I'm not confident any of this is a good idea; luckily this isn't the python-good-ideas-only list. Phew!
>> Just for the fun of it, here's my offering:
>>> a := gizmo(arg1, arg2)
>> is equivalent to
>> a = gimzo(arg1, arg2, __name__='a')
>> Advantages:
>> * Doesn't rewrite the order of arguments
> * Keep the current '@' notation unambiguous
> * Still looks like an assignment.
> * Would give a meaningful error message if gizmo() weren't expecting a name
> * Doesn't look like perl
> * Doesn't twist your mind into a pretzel
> * No new keywords
> * Easy to adapt any existing tools that need to know their own name
> * Doesn't seem like magic or spooky action at a distance
> * The program still looks like a Python program
>> Disadvantage:
>> * I'm still not sure that the "problem" is worth solving.
> * Between this and function annotations, it looks like Pascal is coming back.
>>> Raymond
This is the worst suggestion I've seen so far. := ambiguous and gives no
hint as to what it is doing and its use in other languages would add
confusion. := could be used for any kind of "funky assignment". := also
just looks weird.