Fwd: Copy Constructor DIP and implementation

2018-09-11 Thread Andrei Alexandrescu via Digitalmars-d
This should probably have been posted here. -- Andrei Forwarded Message Subject: Copy Constructor DIP and implementation Date: Tue, 11 Sep 2018 15:08:33 + From: RazvanN Organization: Digital Mars Newsgroups: digitalmars.D.announce Hello everyone, I have finished writing

Re: Copy Constructor DIP

2018-07-17 Thread Manu via Digitalmars-d
On Tue, 17 Jul 2018 at 10:20, aliak via Digitalmars-d wrote: > > On Friday, 13 July 2018 at 12:31:41 UTC, Atila Neves wrote: > > On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: > >> On Thu, 12 Jul 2018 at 19:15, Andrei Alexandrescu via > >> Digitalmars-d wrote: > >>> > >>> On 7/12/18 6:34 PM

Re: Copy Constructor DIP

2018-07-17 Thread aliak via Digitalmars-d
On Friday, 13 July 2018 at 12:31:41 UTC, Atila Neves wrote: On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: On Thu, 12 Jul 2018 at 19:15, Andrei Alexandrescu via Digitalmars-d wrote: On 7/12/18 6:34 PM, Manu wrote: > On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via > Digitalmars-d

Re: Copy Constructor DIP

2018-07-17 Thread aliak00 via Digitalmars-d
On Tuesday, 17 July 2018 at 14:41:06 UTC, ag0aep6g wrote: On 07/17/2018 03:03 PM, aliak00 wrote: [...] In a UDA `@implicit`, `implicit` is just a normal symbol. So the normal lookup rules apply. In particular, you can shadow an imported `implicit` with a local one: [...] Ah, gotcha! Than

Re: Copy Constructor DIP

2018-07-17 Thread ag0aep6g via Digitalmars-d
On 07/17/2018 03:03 PM, aliak00 wrote: Can you explain a bit more here? How does having implicit as a compiler recognized UDA avoid breaking changes as opposed to it being implemented like @nogc/@safe (how are those implemented differently anyway?) In a UDA `@implicit`, `implicit` is just a no

Re: Copy Constructor DIP

2018-07-17 Thread Luís Marques via Digitalmars-d
On Saturday, 14 July 2018 at 10:53:17 UTC, Andrei Alexandrescu wrote: I think it's better to choose a more general attribute name with reduced initial applicability. Then application of said attribute can be extended to other functions with ease. In contrast, an obscure attribute name is sure t

Re: Copy Constructor DIP

2018-07-17 Thread aliak00 via Digitalmars-d
On Saturday, 14 July 2018 at 00:57:14 UTC, Andrei Alexandrescu wrote: [...] chucklesomely profligate and ridiculously baroque. Andrei Hahaha this sentence... amazing! :D I was going to propose auto this(ref A other) {} but nevermind :p Cheers, - Ali

Re: Copy Constructor DIP

2018-07-17 Thread aliak00 via Digitalmars-d
On Tuesday, 17 July 2018 at 04:04:33 UTC, Manu wrote: On Mon., 16 Jul. 2018, 6:00 pm docandrew via Digitalmars-d, < digitalmars-d@puremagic.com> wrote: On Saturday, 14 July 2018 at 10:53:17 UTC, Andrei Alexandrescu wrote: > On 7/14/18 5:03 AM, Luís Marques wrote: >> If there is "no other mean

Re: Copy Constructor DIP

2018-07-17 Thread aliak00 via Digitalmars-d
On Tuesday, 17 July 2018 at 07:27:32 UTC, Jacob Carlborg wrote: On Tuesday, 17 July 2018 at 00:04:12 UTC, Andrei Alexandrescu wrote: Then "negative" :o). In brief @implicit follows the same implementation as @safe and @nogc/ Why? This is a breaking change. Why not go with an approach that d

Re: Copy Constructor DIP

2018-07-17 Thread Andrei Alexandrescu via Digitalmars-d
On 7/17/18 12:04 AM, Manu wrote: But that's the point, and the key advantage of the name ;) [:nod:]

Re: Copy Constructor DIP

2018-07-17 Thread Andrei Alexandrescu via Digitalmars-d
On 7/16/18 8:57 PM, docandrew wrote: I think in this case, a more obscure name like @copyctor is more descriptive. On the contrary, it is redundant and uninformative. It applies to exactly a constructor that copies, so it adds no information. "@implicit" describes precisely what the attribute

Re: Copy Constructor DIP

2018-07-17 Thread Jacob Carlborg via Digitalmars-d
On Tuesday, 17 July 2018 at 00:04:12 UTC, Andrei Alexandrescu wrote: Then "negative" :o). In brief @implicit follows the same implementation as @safe and @nogc/ Why? This is a breaking change. Why not go with an approach that does not cause any breaking changes, which is just as easy to do?

Re: Copy Constructor DIP

2018-07-16 Thread Manu via Digitalmars-d
On Mon., 16 Jul. 2018, 6:00 pm docandrew via Digitalmars-d, < digitalmars-d@puremagic.com> wrote: > On Saturday, 14 July 2018 at 10:53:17 UTC, Andrei Alexandrescu > wrote: > > On 7/14/18 5:03 AM, Luís Marques wrote: > >> If there is "no other meaning of @implicit" (other than the > >> intersection

Re: Copy Constructor DIP

2018-07-16 Thread docandrew via Digitalmars-d
On Saturday, 14 July 2018 at 10:53:17 UTC, Andrei Alexandrescu wrote: On 7/14/18 5:03 AM, Luís Marques wrote: If there is "no other meaning of @implicit" (other than the intersection of those two properties) why don't you just call it something like @copyctor? I'm totally cool with giving the

Re: Copy Constructor DIP

2018-07-16 Thread Andrei Alexandrescu via Digitalmars-d
On 7/16/18 3:12 PM, ag0aep6g wrote: On 07/16/2018 09:06 PM, Andrei Alexandrescu wrote: On 7/14/18 11:26 AM, Jacob Carlborg wrote: [...] That's easily fixed by implementing a compiler recognized UDA. That would mean that it would only be a copy constructor if "implicit" is defined in core.attr

Re: Copy Constructor DIP

2018-07-16 Thread ag0aep6g via Digitalmars-d
On 07/16/2018 09:06 PM, Andrei Alexandrescu wrote: On 7/14/18 11:26 AM, Jacob Carlborg wrote: [...] That's easily fixed by implementing a compiler recognized UDA. That would mean that it would only be a copy constructor if "implicit" is defined in core.attribute. This would also avoid any spec

Re: Copy Constructor DIP

2018-07-16 Thread Andrei Alexandrescu via Digitalmars-d
On 7/14/18 11:26 AM, Jacob Carlborg wrote: On Friday, 13 July 2018 at 01:18:48 UTC, Andrei Alexandrescu wrote: On 7/12/18 2:30 PM, ag0aep6g wrote: You're still potentially changing the semantics of existing code. `@implicit` can be a UDA today: enum implicit = 0; struct C { @impli

Re: Copy Constructor DIP

2018-07-15 Thread sclytrack via Digitalmars-d
On Friday, 13 July 2018 at 11:02:57 UTC, RazvanN wrote: [...] Indeed, but this was the source of the problem also, because you could modify immutable fields that way. [...] Affirmative. The DIP needs to specify how assignment is handled if no opAssign is present but a copy ctor is presen

Re: Copy Constructor DIP

2018-07-14 Thread Jacob Carlborg via Digitalmars-d
On Friday, 13 July 2018 at 01:18:48 UTC, Andrei Alexandrescu wrote: On 7/12/18 2:30 PM, ag0aep6g wrote: You're still potentially changing the semantics of existing code. `@implicit` can be a UDA today: enum implicit = 0; struct C {     @implicit this(ref C another) {} } Today, th

Re: Copy Constructor DIP

2018-07-14 Thread rikki cattermole via Digitalmars-d
On 14/07/2018 11:49 PM, Johan Engelen wrote: On Saturday, 14 July 2018 at 10:53:17 UTC, Andrei Alexandrescu wrote: I now deeply regret ever telling Razvan to mention future possible directions. This DIP must do implicit copy constructors and do it well, nothing less and nothing more. Strong

Re: Copy Constructor DIP

2018-07-14 Thread Johan Engelen via Digitalmars-d
On Saturday, 14 July 2018 at 10:53:17 UTC, Andrei Alexandrescu wrote: I now deeply regret ever telling Razvan to mention future possible directions. This DIP must do implicit copy constructors and do it well, nothing less and nothing more. Strongly agree with this. In my review on Github I h

Re: Copy Constructor DIP

2018-07-14 Thread Andrei Alexandrescu via Digitalmars-d
On 7/14/18 5:03 AM, Luís Marques wrote: If there is "no other meaning of @implicit" (other than the intersection of those two properties) why don't you just call it something like @copyctor? I'm totally cool with giving the attribute a more obscure name such as @copyctor or anything people wa

Re: Copy Constructor DIP

2018-07-14 Thread Manu via Digitalmars-d
On Sat., 14 Jul. 2018, 2:00 am rikki cattermole via Digitalmars-d, < digitalmars-d@puremagic.com> wrote: > On 14/07/2018 1:04 PM, Manu wrote: > > Determining that requires at least a cursory exploration. > > Given how many of us are objecting to the syntax, I'm going to place > this requirement up

Re: Copy Constructor DIP

2018-07-14 Thread Luís Marques via Digitalmars-d
On Saturday, 14 July 2018 at 00:41:37 UTC, Andrei Alexandrescu wrote: The specification of @implicit is in the DIP in full: a constructor that takes by reference a qualified typeof(this) and has the @implicit attribute will be callable implicitly by the compiler. There is no other meaning of @i

Re: Copy Constructor DIP

2018-07-14 Thread rikki cattermole via Digitalmars-d
On 14/07/2018 1:04 PM, Manu wrote: Determining that requires at least a cursory exploration. Given how many of us are objecting to the syntax, I'm going to place this requirement upon a 'yes' answer by me. That an attempt is made for an alternative syntax discussion. It's a fair request I thi

Re: Copy Constructor DIP

2018-07-13 Thread Manu via Digitalmars-d
On Fri, 13 Jul 2018 at 18:00, Andrei Alexandrescu via Digitalmars-d wrote: > > On 7/13/18 5:49 PM, rikki cattermole wrote: > > On 14/07/2018 9:28 AM, Manu wrote: > >> I've already contributed other points to this DIP in the way you > >> describe. > >> This one however is very strange, and I'm surp

Re: Copy Constructor DIP

2018-07-13 Thread Manu via Digitalmars-d
On Fri, 13 Jul 2018 at 17:45, Andrei Alexandrescu via Digitalmars-d wrote: > > On 7/13/18 5:28 PM, Manu wrote: > > As I originally said, my feedback is concrete: specify @implicit, this > > DIP depends on it. > > The specification of @implicit is in the DIP in full: a constructor that > takes by r

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/13/18 5:49 PM, rikki cattermole wrote: On 14/07/2018 9:28 AM, Manu wrote: I've already contributed other points to this DIP in the way you describe. This one however is very strange, and I'm surprised you can find the hand-wavy introduction of a new attribute without any sense of where it'

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/13/18 5:28 PM, Manu wrote: As I originally said, my feedback is concrete: specify @implicit, this DIP depends on it. The specification of @implicit is in the DIP in full: a constructor that takes by reference a qualified typeof(this) and has the @implicit attribute will be callable impli

Re: Copy Constructor DIP

2018-07-13 Thread Meta via Digitalmars-d
On Friday, 13 July 2018 at 21:49:57 UTC, rikki cattermole wrote: On 14/07/2018 9:28 AM, Manu wrote: I've already contributed other points to this DIP in the way you describe. This one however is very strange, and I'm surprised you can find the hand-wavy introduction of a new attribute without a

Re: Copy Constructor DIP

2018-07-13 Thread rikki cattermole via Digitalmars-d
On 14/07/2018 9:28 AM, Manu wrote: I've already contributed other points to this DIP in the way you describe. This one however is very strange, and I'm surprised you can find the hand-wavy introduction of a new attribute without any sense of where it's going to be okay. Or maybe, I'm surprised I'

Re: Copy Constructor DIP

2018-07-13 Thread Manu via Digitalmars-d
On Fri, 13 Jul 2018 at 07:35, Andrei Alexandrescu via Digitalmars-d wrote: > > On 7/12/18 11:45 PM, Manu wrote: > > > > I can see myself getting behind 2 possibilities, no @implicit, or > > @implicit done right. > > A couple of simple ideas are making the process productive. One is to > rely on fa

Re: Copy Constructor DIP

2018-07-13 Thread Luís Marques via Digitalmars-d
On Friday, 13 July 2018 at 18:54:48 UTC, Manu wrote: As a marker used in this one case, it's a terrible name, as a generalised concept, it's perfect. Exactly.

Re: Copy Constructor DIP

2018-07-13 Thread Manu via Digitalmars-d
On Fri, 13 Jul 2018 at 10:35, Atila Neves via Digitalmars-d wrote: > > [...] > > Now that I understand the implicit call `@implicit` makes sense > to me but I'm convinced it'll confuse more people than not. I'll > see if I can come up with a better name. You don't find 'implicit' satisfactory as

Re: Copy Constructor DIP

2018-07-13 Thread Manu via Digitalmars-d
On Fri, 13 Jul 2018 at 07:40, Andrei Alexandrescu via Digitalmars-d wrote: > > On 7/12/18 11:01 PM, Manu wrote: > > What existing code are you changing the semantics of? > > It's still not clear to me how accepting `this(ref T)` as a magic > > signature that is a copy constructor can break existin

Re: Copy Constructor DIP

2018-07-13 Thread Manu via Digitalmars-d
On Fri, 13 Jul 2018 at 04:05, RazvanN via Digitalmars-d wrote: > > > [...] > > The problem with this approach is that some copy constructors > will also be used as assignment operators while others will not, > but with good error messages it could be handled (error on line > `f = d` : opAssign not

Re: Copy Constructor DIP

2018-07-13 Thread Atila Neves via Digitalmars-d
On Friday, 13 July 2018 at 16:02:51 UTC, Andrei Alexandrescu wrote: On 7/13/18 11:14 AM, Atila Neves wrote: On Friday, 13 July 2018 at 14:12:59 UTC, Andrei Alexandrescu wrote: On 7/13/18 8:31 AM, Atila Neves wrote: On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: [...] https://github.co

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/13/18 12:06 PM, xenon325 wrote: From the DIP: The copy constructor declaration will be recognized by the parser when the tokens @, implicit, this are encountered exactly in this order Regarding "exactly in this order". The code below would be allowed and define copy c'tor for `A` and us

Re: Copy Constructor DIP

2018-07-13 Thread xenon325 via Digitalmars-d
From the DIP: The copy constructor declaration will be recognized by the parser when the tokens @, implicit, this are encountered exactly in this order Regarding "exactly in this order". The code below would be allowed and define copy c'tor for `A` and usual c'tor for `B` ? struct impl

Re: Copy Constructor DIP

2018-07-13 Thread 12345swordy via Digitalmars-d
On Friday, 13 July 2018 at 16:02:51 UTC, Andrei Alexandrescu wrote: On 7/13/18 11:14 AM, Atila Neves wrote: [...] Great. Razvan, can you please add this example with discussion to the DIP (probably at the end of the Motivation section as an explanation why we need the addition of @implicit).

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/13/18 11:14 AM, Atila Neves wrote: On Friday, 13 July 2018 at 14:12:59 UTC, Andrei Alexandrescu wrote: On 7/13/18 8:31 AM, Atila Neves wrote: On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: [...] https://github.com/search?q=%22this%5C%28ref%22+language%3AD&type=Code The answer see

Re: Copy Constructor DIP

2018-07-13 Thread Atila Neves via Digitalmars-d
On Friday, 13 July 2018 at 14:12:59 UTC, Andrei Alexandrescu wrote: On 7/13/18 8:31 AM, Atila Neves wrote: On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: [...] https://github.com/search?q=%22this%5C%28ref%22+language%3AD&type=Code The answer seems to be: not many. Most of the results a

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 11:01 PM, Manu wrote: What existing code are you changing the semantics of? It's still not clear to me how accepting `this(ref T)` as a magic signature that is a copy constructor can break existing code? Is it the unlikely^^2 case that the function exists somewhere and doesn't perform

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 11:45 PM, Manu wrote: On Thu, 12 Jul 2018 at 20:15, Meta via Digitalmars-d wrote: On Friday, 13 July 2018 at 02:32:59 UTC, Manu wrote: Seriously, if I was making this proposal to you, and you were in my position... there is no way in hell that you'd allow any of us to slip somethin

Re: Copy Constructor DIP

2018-07-13 Thread Andrei Alexandrescu via Digitalmars-d
On 7/13/18 8:31 AM, Atila Neves wrote: On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: On Thu, 12 Jul 2018 at 19:15, Andrei Alexandrescu via Digitalmars-d wrote: On 7/12/18 6:34 PM, Manu wrote: > On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via > Digitalmars-d wrote: >> [..] doe

Re: Copy Constructor DIP

2018-07-13 Thread Atila Neves via Digitalmars-d
On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote: On Thu, 12 Jul 2018 at 19:15, Andrei Alexandrescu via Digitalmars-d wrote: On 7/12/18 6:34 PM, Manu wrote: > On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via > Digitalmars-d wrote: >> [..] doesn't perform copy construction? 1. the

Re: Copy Constructor DIP

2018-07-13 Thread RazvanN via Digitalmars-d
In a post-blit world, with no opAssign specified, postblit will call for copy construction AND for assignment, thereby assignment is always correct. Once postblit is swapped for a copy-constructor, absence of opAssign will result in invalid behaviour on assignment. Indeed, but this was the s

Re: Copy Constructor DIP

2018-07-13 Thread RazvanN via Digitalmars-d
The above code contains a typo. The parameter type of the second copy constructor is meant to be B not A

Re: Copy Constructor DIP

2018-07-13 Thread meppl via Digitalmars-d
On Thursday, 12 July 2018 at 20:29:43 UTC, Manu wrote: On Wed, 11 Jul 2018 at 23:55, RazvanN via Digitalmars-d wrote: > What's wrong with: > struct S { > this(ref S copyFrom); > } > > That looks like a perfectly good copy constructor > declaration ;) I'm just saying, the DIP needs to explai

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 20:15, Meta via Digitalmars-d wrote: > > On Friday, 13 July 2018 at 02:32:59 UTC, Manu wrote: > > Seriously, if I was making this proposal to you, and you were > > in my > > position... there is no way in hell that you'd allow any of us > > to slip > > something so substanti

Re: Copy Constructor DIP

2018-07-12 Thread Meta via Digitalmars-d
On Friday, 13 July 2018 at 02:32:59 UTC, Manu wrote: Seriously, if I was making this proposal to you, and you were in my position... there is no way in hell that you'd allow any of us to slip something so substantial by like that with the wave of a hand. This DIP depends on @implicit. How can y

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 19:15, Andrei Alexandrescu via Digitalmars-d wrote: > > On 7/12/18 6:34 PM, Manu wrote: > > On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via Digitalmars-d > > wrote: > >> > >> On 07/11/2018 11:11 AM, Atila Neves wrote: > >>> On Wednesday, 11 July 2018 at 07:40:32 UTC,

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu., 12 Jul. 2018, 7:10 pm Andrei Alexandrescu via Digitalmars-d, < digitalmars-d@puremagic.com> wrote: > On 7/12/18 7:15 PM, Manu wrote: > > On Thu, 12 Jul 2018 at 08:36, Andrei Alexandrescu via Digitalmars-d > > wrote: > >> > >> On 07/12/2018 11:14 AM, Luís Marques wrote: > >>> On Thursday,

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 10:05 PM, Manu wrote: On Thu, 12 Jul 2018 at 18:25, Andrei Alexandrescu via Digitalmars-d wrote: On 7/12/18 4:29 PM, Manu wrote: Being able to implement them both independently is*occasionally* useful, but 95% of the time, destruct + copy-construct is an equally efficient implement

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 6:37 PM, Manu wrote: On Thu, 12 Jul 2018 at 07:15, Andrei Alexandrescu via Digitalmars-d wrote: On 07/12/2018 09:49 AM, Atila Neves wrote: On Thursday, 12 July 2018 at 06:54:37 UTC, RazvanN wrote: [...] If by "come in pairs" you mean that you can define them both, then yes, th

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 6:34 PM, Manu wrote: On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via Digitalmars-d wrote: On 07/11/2018 11:11 AM, Atila Neves wrote: On Wednesday, 11 July 2018 at 07:40:32 UTC, RazvanN wrote: But there's a super explicit `@implicit` thing written right there... so should we

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 7:15 PM, Manu wrote: On Thu, 12 Jul 2018 at 08:36, Andrei Alexandrescu via Digitalmars-d wrote: On 07/12/2018 11:14 AM, Luís Marques wrote: On Thursday, 12 July 2018 at 14:56:33 UTC, Luís Marques wrote: When designing D libraries than lean towards DSL style, I've frequently felt i

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 18:25, Andrei Alexandrescu via Digitalmars-d wrote: > > On 7/12/18 4:29 PM, Manu wrote: > > Being able to implement them both independently is*occasionally* > > useful, but 95% of the time, destruct + copy-construct is an equally > > efficient implementation for assignment.

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 4:29 PM, Manu wrote: Being able to implement them both independently is*occasionally* useful, but 95% of the time, destruct + copy-construct is an equally efficient implementation for assignment. I'd suggest that this destruct+copy-construct pattern is a perfectly good substitute for a

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 2:30 PM, ag0aep6g wrote: On 07/12/2018 03:40 PM, Andrei Alexandrescu wrote: On 07/10/2018 04:58 PM, Manu wrote: [...] 1. Explain the need and reasoning behind `@implicit`. Razvan: I think it would help to explain that the attribute is necessary to avoid changing semantics of exis

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 08:36, Andrei Alexandrescu via Digitalmars-d wrote: > > On 07/12/2018 11:14 AM, Luís Marques wrote: > > On Thursday, 12 July 2018 at 14:56:33 UTC, Luís Marques wrote: > >> When designing D libraries than lean towards DSL style, I've > >> frequently felt impaired by the lack

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 08:30, Luís Marques via Digitalmars-d wrote: > > On Thursday, 12 July 2018 at 15:14:19 UTC, Luís Marques wrote: > > More details. The DIP says: > > > > "The structName type needs to be identical to typeof(this); an > > error is issued otherwise. This requirement may be relax

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Tue, 10 Jul 2018 at 03:50, RazvanN via Digitalmars-d wrote: > > Hi everyone! > > I managed to put together a first draft of the DIP for adding the > copy constructor to the language [1]. If anyone is interested, > please take a look. Suggestions and comments about technical > aspects and wordin

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via Digitalmars-d wrote: > > On 07/11/2018 11:11 AM, Atila Neves wrote: > > On Wednesday, 11 July 2018 at 07:40:32 UTC, RazvanN wrote: > >>> But there's a super explicit `@implicit` thing written right there... > >>> so should we expect that an *ex

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 07:15, Andrei Alexandrescu via Digitalmars-d wrote: > > On 07/12/2018 09:49 AM, Atila Neves wrote: > > On Thursday, 12 July 2018 at 06:54:37 UTC, RazvanN wrote: > > > >> [...] > > > >> If by "come in pairs" you mean that you can define them both, then yes, > >> that is the c

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via Digitalmars-d wrote: > > On 07/11/2018 11:11 AM, Atila Neves wrote: > > On Wednesday, 11 July 2018 at 07:40:32 UTC, RazvanN wrote: > >>> But there's a super explicit `@implicit` thing written right there... > >>> so should we expect that an *ex

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Thu, 12 Jul 2018 at 06:45, Andrei Alexandrescu via Digitalmars-d wrote: > > On 07/10/2018 06:50 PM, Manu wrote: > > On Tue, 10 Jul 2018 at 15:23, Jonathan M Davis via Digitalmars-d > > wrote: > >> > >> On Tuesday, 10 July 2018 14:58:09 MDT Manu via Digitalmars-d wrote: > >>> 2. It looks like c

Re: Copy Constructor DIP

2018-07-12 Thread Manu via Digitalmars-d
On Wed, 11 Jul 2018 at 23:55, RazvanN via Digitalmars-d wrote: > > > What's wrong with: > > struct S { > > this(ref S copyFrom); > > } > > > > That looks like a perfectly good copy constructor declaration > > ;) I'm just saying, the DIP needs to explain this. > > That is actually a valid constru

Re: Copy Constructor DIP

2018-07-12 Thread ag0aep6g via Digitalmars-d
On 07/12/2018 03:40 PM, Andrei Alexandrescu wrote: On 07/10/2018 04:58 PM, Manu wrote: [...] 1. Explain the need and reasoning behind `@implicit`. Razvan: I think it would help to explain that the attribute is necessary to avoid changing semantics of existing code. Thanks. You're still pot

Re: Copy Constructor DIP

2018-07-12 Thread Johannes Pfau via Digitalmars-d
Am Thu, 12 Jul 2018 17:32:06 + schrieb Johannes Pfau: > Am Thu, 12 Jul 2018 09:48:37 -0400 schrieb Andrei Alexandrescu: > >>> I agree that the current syntax is lacking. This was Andrei's >>> proposition and I was initially against it, but he said to put it in >>> the DIP so that we can discu

Re: Copy Constructor DIP

2018-07-12 Thread Johannes Pfau via Digitalmars-d
Am Thu, 12 Jul 2018 09:48:37 -0400 schrieb Andrei Alexandrescu: >> I agree that the current syntax is lacking. This was Andrei's >> proposition and I was initially against it, but he said to put it in >> the DIP so that we can discuss it as a community. Maybe this syntax is >> better: >> >> @this

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 7/12/18 11:42 AM, Luís Marques wrote: On Thursday, 12 July 2018 at 15:33:03 UTC, Andrei Alexandrescu wrote: Again: not the charter of this DIP, so you should ask yourself, not us, this question. Look, I understand it can be frustrating to have a concrete design proposal derailed by a myria

Re: Copy Constructor DIP

2018-07-12 Thread jmh530 via Digitalmars-d
On Thursday, 12 July 2018 at 15:42:29 UTC, Luís Marques wrote: On Thursday, 12 July 2018 at 15:33:03 UTC, Andrei Alexandrescu wrote: Again: not the charter of this DIP, so you should ask yourself, not us, this question. Look, I understand it can be frustrating to have a concrete design propos

Re: Copy Constructor DIP

2018-07-12 Thread Luís Marques via Digitalmars-d
On Thursday, 12 July 2018 at 15:33:03 UTC, Andrei Alexandrescu wrote: Again: not the charter of this DIP, so you should ask yourself, not us, this question. Look, I understand it can be frustrating to have a concrete design proposal derailed by a myriad of speculative questions. But if we sus

Re: Copy Constructor DIP

2018-07-12 Thread Luís Marques via Digitalmars-d
On Thursday, 12 July 2018 at 15:34:25 UTC, Andrei Alexandrescu wrote: The DIP mentions the interaction of @implicit with alias this. Not the interaction I was asking about, although admittedly it was speculative.

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 11:14 AM, Luís Marques wrote: On Thursday, 12 July 2018 at 14:56:33 UTC, Luís Marques wrote: When designing D libraries than lean towards DSL style, I've frequently felt impaired by the lack of implicit conversions in D. In my experience, it's not that all types need to be implici

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 11:29 AM, Luís Marques wrote: On Thursday, 12 July 2018 at 15:25:10 UTC, Luís Marques wrote: On Thursday, 12 July 2018 at 15:14:19 UTC, Luís Marques wrote: BTW: Multiple alias this is still planned for inclusion in D, right? If so, what would be the (pratical?) difference between

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 11:25 AM, Luís Marques wrote: On Thursday, 12 July 2018 at 15:14:19 UTC, Luís Marques wrote: More details. The DIP says: "The structName type needs to be identical to typeof(this); an error is issued otherwise. This requirement may be relaxed in the future in order to accomodate

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 11:22 AM, Timon Gehr wrote: On 12.07.2018 15:29, Andrei Alexandrescu wrote: On 07/11/2018 05:55 AM, Nick Treleaven wrote: ... Removing `static` works. Otherwise I tried changing `ref` to `alias`: Error: variable src cannot be read at compile time But this shorter code seems to

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 10:54 AM, Jonathan M Davis wrote: On Thursday, 12 July 2018 07:45:30 MDT Andrei Alexandrescu via Digitalmars-d wrote: I also very much dislike the syntax - it makes no sense to me at all. I commented on the PR itself asking why it differs so much from C++ - specifically, what's bad

Re: Copy Constructor DIP

2018-07-12 Thread Timon Gehr via Digitalmars-d
On 12.07.2018 17:22, Timon Gehr wrote: alias field0 = s.tupleof[0]; t.tupleof[0] = field0; alias field1 = s.tupleof[1]; t.tupleof[1] = field1; alias field2 = s.tupleof[2]; t.tupleof[2] = field2; Error: alias `a` cannot alias an expression `tuple(s.a, s.b, s.c)[0]` Error: alias `b` cannot alias

Re: Copy Constructor DIP

2018-07-12 Thread Luís Marques via Digitalmars-d
On Thursday, 12 July 2018 at 15:25:10 UTC, Luís Marques wrote: On Thursday, 12 July 2018 at 15:14:19 UTC, Luís Marques wrote: BTW: Multiple alias this is still planned for inclusion in D, right? If so, what would be the (pratical?) difference between having copy ctors with such a relaxed type r

Re: Copy Constructor DIP

2018-07-12 Thread Luís Marques via Digitalmars-d
On Thursday, 12 July 2018 at 15:14:19 UTC, Luís Marques wrote: More details. The DIP says: "The structName type needs to be identical to typeof(this); an error is issued otherwise. This requirement may be relaxed in the future in order to accomodate copying from objects of a different type"

Re: Copy Constructor DIP

2018-07-12 Thread Timon Gehr via Digitalmars-d
On 12.07.2018 15:29, Andrei Alexandrescu wrote: On 07/11/2018 05:55 AM, Nick Treleaven wrote: ... Removing `static` works. Otherwise I tried changing `ref` to `alias`: Error: variable src cannot be read at compile time But this shorter code seems to work fine: this.tupleof = src.tupleof; O

Re: Copy Constructor DIP

2018-07-12 Thread Luís Marques via Digitalmars-d
On Thursday, 12 July 2018 at 14:56:33 UTC, Luís Marques wrote: When designing D libraries than lean towards DSL style, I've frequently felt impaired by the lack of implicit conversions in D. In my experience, it's not that all types need to be implicitly convertible to other types. Just being a

Re: Copy Constructor DIP

2018-07-12 Thread Luís Marques via Digitalmars-d
On Tuesday, 10 July 2018 at 10:47:04 UTC, RazvanN wrote: I managed to put together a first draft of the DIP for adding the copy constructor to the language [1]. If anyone is interested, please take a look. Suggestions and comments about technical aspects and wording are all welcome. When desi

Re: Copy Constructor DIP

2018-07-12 Thread Jonathan M Davis via Digitalmars-d
On Thursday, 12 July 2018 07:45:30 MDT Andrei Alexandrescu via Digitalmars-d wrote: > > I also very much dislike the syntax - it makes no sense to me at all. I > > commented on the PR itself asking why it differs so much from C++ - > > specifically, what's bad about the C++ way of doing things the

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 09:49 AM, Atila Neves wrote: On Thursday, 12 July 2018 at 06:54:37 UTC, RazvanN wrote: [...] If by "come in pairs" you mean that you can define them both, then yes, that is the case. Will add a paragraph in the DIP to specify this. You mentioned that it's terrible that the ass

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/11/2018 12:19 PM, vit wrote: On Wednesday, 11 July 2018 at 07:40:32 UTC, RazvanN wrote: But there's a super explicit `@implicit` thing written right there... so should we expect that an *explicit* call to the copy constructor is not allowed? Or maybe it is allowed and `@implicit` is a lie

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/11/2018 05:28 PM, Manu wrote: What's wrong with: struct S { this(ref S copyFrom); } That looks like a perfectly good copy constructor declaration ;) I'm just saying, the DIP needs to explain this. Thanks, worth a paragraph discussing silent semantics change. Right. This is all obvio

Re: Copy Constructor DIP

2018-07-12 Thread Atila Neves via Digitalmars-d
On Thursday, 12 July 2018 at 06:54:37 UTC, RazvanN wrote: [...] If by "come in pairs" you mean that you can define them both, then yes, that is the case. Will add a paragraph in the DIP to specify this. You mentioned that it's terrible that the assignment operator and the copy constructor

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/12/2018 02:54 AM, RazvanN wrote: What's wrong with: struct S {   this(ref S copyFrom); } That looks like a perfectly good copy constructor declaration ;) I'm just saying, the DIP needs to explain this. That is actually a valid constructor, according to today's compiler. There might be c

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/11/2018 11:11 AM, Atila Neves wrote: On Wednesday, 11 July 2018 at 07:40:32 UTC, RazvanN wrote: But there's a super explicit `@implicit` thing written right there... so should we expect that an *explicit* call to the copy constructor is not allowed? Or maybe it is allowed and `@implicit`

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/10/2018 06:50 PM, Manu wrote: On Tue, 10 Jul 2018 at 15:23, Jonathan M Davis via Digitalmars-d wrote: On Tuesday, 10 July 2018 14:58:09 MDT Manu via Digitalmars-d wrote: 2. It looks like copy constructors are used to perform assignments (and not constructions)... but, there is also opAs

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/10/2018 04:58 PM, Manu wrote: On Tue, 10 Jul 2018 at 03:50, RazvanN via Digitalmars-d wrote: Hi everyone! I managed to put together a first draft of the DIP for adding the copy constructor to the language [1]. If anyone is interested, please take a look. Suggestions and comments about t

Re: Copy Constructor DIP

2018-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/11/2018 05:55 AM, Nick Treleaven wrote: On Tuesday, 10 July 2018 at 10:47:04 UTC, RazvanN wrote: [1] https://github.com/dlang/DIPs/pull/129 Thanks for making the DIP. I can't get this code to compile (my struct has an `int i` field): static foreach (i, ref field; src.tupleof)     thi

Re: Copy Constructor DIP

2018-07-12 Thread RazvanN via Digitalmars-d
That's my point; so this is a compile error then: S b = S(a); // <- explicit construction of copy? ie, explicit call to stated `@implicit` function Consider this code: import std.stdio : writeln; struct S { this(this) { writeln("postblit"); } int a; this(int a)

Re: Copy Constructor DIP

2018-07-11 Thread RazvanN via Digitalmars-d
What's wrong with: struct S { this(ref S copyFrom); } That looks like a perfectly good copy constructor declaration ;) I'm just saying, the DIP needs to explain this. That is actually a valid constructor, according to today's compiler. There might be code out there that uses this syntax for

Re: Copy Constructor DIP

2018-07-11 Thread Manu via Digitalmars-d
On Wed, 11 Jul 2018 at 09:20, vit via Digitalmars-d wrote: > > On Wednesday, 11 July 2018 at 07:40:32 UTC, RazvanN wrote: > >> But there's a super explicit `@implicit` thing written right > >> there... so should we expect that an *explicit* call to the > >> copy constructor is not allowed? Or mayb

Re: Copy Constructor DIP

2018-07-11 Thread Manu via Digitalmars-d
On Wed, 11 Jul 2018 at 00:45, RazvanN via Digitalmars-d wrote: > > > But there's a super explicit `@implicit` thing written right > > there... so should we expect that an *explicit* call to the > > copy constructor is not allowed? Or maybe it is allowed and > > `@implicit` is a lie? > > The @impli

  1   2   >