[Python-ideas] Dart-like method cascading operator in Python
Bruce Leban
bruce at leapyear.org
Thu Nov 21 23:55:24 CET 2013
I like the basic idea. I agree with the sentiment that a colon should be
used to introduce it. Let me throw out some monkey wrenches. The following
uses :: as the syntax to begin the suite, that is:
obj::
..a = 1
is equivalent to
temp = obj
temp.a = 1
I'm assuming the .. must be followed by a statement (rewritten as above)
except in the case where the line ends with :: in which case it must be an
expression as in the example:
gnuplot.newPlot()::
..newPlot()::
..adjustPlot('x') ###
..adjustPlot('y')
is
temp1 = gnuplot.newPlot()
temp2 = temp1.newPlot()
temp2.adjustPlot('x') ###
temp1.adjustPlot('y')
Is there any way on the line marked ### to reference temp1?
Can I use .. in the middle of a statement/expression?
obj::
x = ..x
y = ..y + ..z
..f(..a, ..b)
equivalent to
temp = obj
x = temp.x
y = temp.y + temp.z
temp.f(temp.a, temp.b)
Is field/method access the only time where this is useful? Can I do this?
obj::
.['a'] = 1
.['b'] = 2
equivalent to
temp = obj
temp['a'] = 1
temp['b'] = 2
or this?
obj::
.(1, 2)
equivalent to
temp = obj
obj(1, 2)
What about this very common code:
self.x = x
self.y = y
self.z = z + 1
it would be nice to have a shorthand for this that didn't require writing x
and y twice, but this doesn't do it for me and I don't have a better
suggestion:
self::
.. = x
.. = y
..z = z + 1
--- Bruce
I'm hiring: http://www.cadencemd.com/info/jobs
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131121/395f0370/attachment.html>
More information about the Python-ideas
mailing list