[Python-ideas] Adding __getter__ to compliment __iter__.
Ron Adam
ron3200 at gmail.com
Tue Jul 23 01:29:18 CEST 2013
On 07/22/2013 01:37 AM, Stephen J. Turnbull wrote:
> Ron Adam writes:
>
> > '+=' is a additive/append type of operation.
>
> Ouch. When '+=' is additive, it's a binary operator on a single set.
> As such, it should take a sequence on both sides (assuming for the
> moment on wants to use it on sequences at all), and thus would
> correspond to concatenation (ie, list.extend()). list.append() and
> set.add() take things of different types, a container on the left and
> an object on the right (at least, if you made them into assignment
> operators, that's what they'd do).
Hmmm, there was a reason I ruled that out.. I think in the initial version
I was doing this...
result = start << (a, b, c)
Where a, b, and c are sequences to be joined to start.
> > A much less used symbol is __lshift__ , '<<'.
>
> But *shift is precisely the opposite: it takes a container on the left
> (eg, a word thought of as a bitstream) and a shifter (usually a
> number) on the right. I guess that's why Stroustrup (or whoever)
> chose left-shift for his iostream operators. So my intuition is
> precisely the opposite of yours as far as choice of spelling goes.
> For strings or lists, "<<=" would append an element, and "+=" would
> extend using a list.
'<<=' is a binary shift. Why would that mean append? Normally you can't
chain '+=', or '<<=' in an expression.
I think the meaning or context I'm trying to get is ...
send y to x == x <-- y
And have what x does with y not be so strictly defined. The '<<' symbol is
closer to '<--' visually without adding a new symbol to python.
> In any case the discussion is moot: the operator "+=" already has the
> definition I find more intuitive for the built-in sequence types.
>
> > And interesting alternative possibility is a concatenation_comprehension.
> > Or cat_comp for short.
> >
> > >>> ("One " << "Two " << "Three!")
> > 'One Two Three!'
> That's not a comprehension. A comprehension aggregates (and possibly
> transforms and filters) the elements of a container. Here the strings
> are elements listed explicitly; it's just an ordinary expression as
> far as anybody who doesn't know how magic "<<" is would know.
I agree, it would need something to signify it isn't just an ordinary
expression.
Cheers,
Ron
More information about the Python-ideas
mailing list