Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Alexandre Brault
On 2017-01-23 12:54 PM, Soni L. wrote: > On 23/01/17 02:56 PM, Gerald Britton wrote: >> On Jan 23, 2017 11:07 AM, "Soni L." > > wrote: >> >> On 23/01/17 01:52 PM, Gerald Britton wrote: >>> >>> [snip] >>> >>> >>> >>>

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Soni L.
On 23/01/17 02:56 PM, Gerald Britton wrote: On Jan 23, 2017 11:07 AM, "Soni L." > wrote: On 23/01/17 01:52 PM, Gerald Britton wrote: [snip] >I propose `x .= y` -> `x = x . y`, for any `y`. [snip]

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Gerald Britton
On Jan 23, 2017 11:07 AM, "Soni L." wrote: On 23/01/17 01:52 PM, Gerald Britton wrote: [snip] >I propose `x .= y` -> `x = x . y`, for any `y`. [snip] I think you mean "any y that is a member of x" Since it desugars into `x = x.y`, you can literally use

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Guido van Rossum
On Mon, Jan 23, 2017 at 8:07 AM, Soni L. wrote: > > > Since it desugars into `x = x.y`, you can literally use anything for `y`. > > x .= __call__().whatever().unwrap() * 3 > > is equivalent to > > x = x.__call__().whatever().unwrap() * 3 > > and > > x .= 1 > > is equivalent

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Soni L.
On 23/01/17 01:52 PM, Gerald Britton wrote: [snip] >I propose `x .= y` -> `x = x . y`, for any `y`. [snip] I think you mean "any y that is a member of x" Since it desugars into `x = x.y`, you can literally use anything for `y`. x .= __call__().whatever().unwrap() * 3

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Ethan Furman
On 01/23/2017 05:33 AM, Soni L. wrote: It's literally sugar for repeating the name and moving the dot to the right. I think it's clearer than most other compound operators in that it doesn't affect precedence rules. `x += y`, for any code `y`, is equivalent to `x = x + (y)`, not `x = x + y`.

[Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Gerald Britton
[snip] >I propose `x .= y` -> `x = x . y`, for any `y`. [snip] I think you mean "any y that is a member of x" Also, note that this syntax means that x will be rebound to the result of calling x.y, whatever that is (frequently, None, for mutating methods) In general, you can't count on

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Wes Turner
On Sunday, January 22, 2017, Wes Turner wrote: > > > On Sunday, January 22, 2017, Soni L. > wrote: > >> >> >> On 22/01/17 10:03 PM, Wes Turner wrote: >> >> >> >> On Sunday, January 22, 2017, Wes

Re: [Python-ideas] Immutable Builder" Pattern and Operator

2017-01-23 Thread Paul Moore
On 23 January 2017 at 13:47, Hervé "Kyle" MUTOMBO wrote: > Paul Moore is clearly right when He says that this "a .= 1+1" doesn't make > sense. It means nothing understandable although in "a .= s(e)" can mean > something. As a matter of fact "a .= EXPR" is bound to

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Random832
On Mon, Jan 23, 2017, at 09:12, Soni L. wrote: > Builders for network connections where you don't wanna start with a > fresh builder every time. Maybe you need a builder builder. Or, more seriously, a way to differentiate the things in the 'builder' from the things that are going to be

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Soni L.
On 23/01/17 11:54 AM, Steven D'Aprano wrote: On Mon, Jan 23, 2017 at 12:49:19AM -0200, Soni L. wrote: [...] You seem to be thinking of "immutable object builder". Not "the builder itself is immutable and operations on it create new builders". Why would you make a builder class immutable?

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Steven D'Aprano
On Mon, Jan 23, 2017 at 12:49:19AM -0200, Soni L. wrote: [...] > You seem to be thinking of "immutable object builder". Not "the builder > itself is immutable and operations on it create new builders". Why would you make a builder class immutable? That's not a rhetorical question -- I'm

Re: [Python-ideas] Immutable Builder" Pattern and Operator

2017-01-23 Thread Kyle
13:26:49 + From: Paul Moore <p.f.mo...@gmail.com> To: "Soni L." <fakedme...@gmail.com> Cc: Python-Ideas <python-ideas@python.org> Subject: Re: [Python-ideas] "Immutable Builder" Pattern and Operator Message-ID:

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread M.-A. Lemburg
On 23.01.2017 14:05, Soni L. wrote: > > > On 23/01/17 09:45 AM, Serhiy Storchaka wrote: >> On 23.01.17 01:30, Soni L. wrote: >>> On 22/01/17 08:54 PM, Serhiy Storchaka wrote: On 23.01.17 00:45, Soni L. wrote: > I've been thinking of an Immutable Builder pattern and an operator > to

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Soni L.
On 23/01/17 09:45 AM, Serhiy Storchaka wrote: On 23.01.17 01:30, Soni L. wrote: On 22/01/17 08:54 PM, Serhiy Storchaka wrote: On 23.01.17 00:45, Soni L. wrote: I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Serhiy Storchaka
On 23.01.17 01:30, Soni L. wrote: On 22/01/17 08:54 PM, Serhiy Storchaka wrote: On 23.01.17 00:45, Soni L. wrote: I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this wouldn't work: long_name = mkbuilder()

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Paul Moore
On 22 January 2017 at 22:45, Soni L. wrote: > I've been thinking of an Immutable Builder pattern and an operator to go > with it. Since the builder would be immutable, this wouldn't work: > > long_name = mkbuilder() > long_name.seta(a) > long_name.setb(b) > y =

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-23 Thread Cory Benfield
> On 22 Jan 2017, at 22:45, Soni L. wrote: > > This pattern is present in the cryptography module already with things like their x509.CertificateBuilder: https://cryptography.io/en/latest/x509/reference/#cryptography.x509.CertificateBuilder

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Wes Turner
On Sunday, January 22, 2017, Soni L. wrote: > > > On 22/01/17 10:03 PM, Wes Turner wrote: > > > > On Sunday, January 22, 2017, Wes Turner > wrote: > >> Have you looked at pyrsistent for >>

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Soni L.
On 22/01/17 10:03 PM, Wes Turner wrote: On Sunday, January 22, 2017, Wes Turner > wrote: Have you looked at pyrsistent for immutable/functional/persistent/copy-on-write data structures in Python?

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Wes Turner
On Sunday, January 22, 2017, Wes Turner wrote: > Have you looked at pyrsistent for > immutable/functional/persistent/copy-on-write > data structures in Python? > > https://github.com/tobgu/pyrsistent/ > > (freeze() / thaw()) > > ... e.g. List and Dict NamedTuple values are

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Wes Turner
Have you looked at pyrsistent for immutable/functional/persistent/copy-on-write data structures in Python? https://github.com/tobgu/pyrsistent/ (freeze() / thaw()) ... e.g. List and Dict NamedTuple values are not immutable (because append() and update() still work) On Sunday, January 22, 2017,

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Ethan Furman
On 01/22/2017 03:30 PM, Soni L. wrote: On 22/01/17 08:54 PM, Serhiy Storchaka wrote: On 23.01.17 00:45, Soni L. wrote: I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this wouldn't work: long_name = mkbuilder()

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Soni L.
On 22/01/17 08:54 PM, Serhiy Storchaka wrote: On 23.01.17 00:45, Soni L. wrote: I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this wouldn't work: long_name = mkbuilder() long_name.seta(a) long_name.setb(b) y =

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Joao S. O. Bueno
This is easy to do in Python, and we already have NamedTuples and other things. If you need such a builder anyway, this snippet can work - no need for special syntax: https://gist.github.com/jsbueno/b2b5f5c06caa915c451253bb4f171ee9 On 22 January 2017 at 20:54, Serhiy Storchaka

Re: [Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Serhiy Storchaka
On 23.01.17 00:45, Soni L. wrote: I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this wouldn't work: long_name = mkbuilder() long_name.seta(a) long_name.setb(b) y = long_name.build() I think the more pythonic way is: y

[Python-ideas] "Immutable Builder" Pattern and Operator

2017-01-22 Thread Soni L.
I've been thinking of an Immutable Builder pattern and an operator to go with it. Since the builder would be immutable, this wouldn't work: long_name = mkbuilder() long_name.seta(a) long_name.setb(b) y = long_name.build() Instead, you'd need something more like this: long_name = mkbuilder()