[Python-ideas] Dart-like method cascading operator in Python

Terry Reedy tjreedy at udel.edu
Thu Nov 21 23:52:58 CET 2013


On 11/21/2013 5:55 AM, Perešíni Peter wrote:
> Recently I fell in love with Dart method cascading operator .. to the
> degree that I find it really convenient and I am missing it in the Python.
> The cascade operator
>
> myObj
>    ..setX(5)
>    ..y=6
>
> is the syntactic sugar equivalent of the following:
>
> tmp = myObj
> tmp.setX(5)
> tmp.y=6

I far prefer
t=<exp>
t.setX(5)
t.y=6

The proposal adds no new functionality.



> can make this much more powerful in Python (as opposed to Dart) because
> Python recognizes scope by indentation

Not true. It recognizes compound statement suites by indentation, 
following a header line ending with ':'.

Name scopes are indicated by class and def statements, and somewhat by 
comprehensions.

> and therefore it would be possible to do something like
>
> gnuplot.newPlot()
>   ..set("xrange [0:5]")
>   ..set("yrange [0:20]")
>   ..newPlot()
>       ..addSeries("Linear", [1,2,3])
>       ..addSeries("Quadratic", [1,4,6])
>   ..run()

This does not look like Python at all ;-).

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list