[Python-ideas] Implementing a set of operation (+, /, - *) on dict consistent with linearAlgebrae

julien tayon julien at tayon.net
Tue Oct 30 18:28:54 EDT 2018


On Tue, 30 Oct 2018 at 22:33, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> julien tayon wrote:
> > like the + of [] could be the + of "RecordAlgebrae"
>
> If you're proposing to change the behaviour of '+' on the
> built-in list type, that's not going to happen.
>
> I dont suggest to change something that already exists and works (I am
pretty conservative too, and expect stuff to not be broken by any changes)
And all behaviours can coexists quite peacefully.

"RecordAlgebra"
In [5]: [2] + [2]
Out[5]: [2, 2]
In [6]: [2] * 2
Out[6]: [2, 2]
In [7]: "a" + "a"
Out[7]: 'aa'
In [8]: "a" * 2
Out[8]: 'aa'
(adding n times the same value is equal to multiplying by n // that is
totally consistent to me)

Mixed scenario :
In [12]: a= mdict(a=[2], b='a')
In [13]: a+a
Out[14]: {'a': [2, 2], b='aa'}
In [17]: a * 4
Out[17]: {'a': [2, 2, 2, 2], b='aaaa'}
I propose the operators to be propagated, and any value to still follow its
logic.
LibearAlgebraic MutableMapping would be as algebraic as their values. No
more.


-- 
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181030/8f799752/attachment.html>


More information about the Python-ideas mailing list