digitalmars.D.announce - DMD 1.035 and 2.019 releases
- Walter Bright (5/5) Sep 02 2008 Struct constructors!
- BCS (2/8) Sep 02 2008 bug soup!!!! :-)
- Matti Niemenmaa (5/9) Sep 02 2008 Nice release, thanks! One nit: running "dmd" still says "Digital Mars D ...
- Walter Bright (2/4) Sep 02 2008 Fixed!
- Georg Wrede (20/28) Sep 04 2008 Congrats, etc., you know! :-)
- Walter Bright (2/3) Sep 05 2008 That's why the default download is for an older version.
- Lionello Lunesu (3/5) Sep 02 2008 Ow, just rename this/~this to ctor/dtor and get it over with! :O
- Extrawurst (4/11) Sep 03 2008 Are opCalls deprecated now ? how do i call the ctor and how the opCall?
- Walter Bright (3/5) Sep 03 2008 To construct an object of struct S:
- Extrawurst (4/11) Sep 03 2008 yeah i figured, but if i have an opCall with the exact same arguments
- Walter Bright (3/15) Sep 03 2008 ctor's override the opCalls. The opCalls will eventually probably get
- Extrawurst (4/20) Sep 03 2008 Well the advandage of opCall is (in my intention) that you can have an
- bobef (3/19) Sep 03 2008 opCalls are much more flexible than ctor's because their return type may...
- 0ffh (4/7) Sep 03 2008 I agree opCalls are more flexible, but unfortunately you can't have both
- Jarrett Billingsley (12/21) Sep 03 2008 Speaking of syntactical ambiguity, the expression
- Walter Bright (5/20) Sep 03 2008 If there's any constructor defined for S, then S(args) is a constructor
- bearophile (6/9) Sep 03 2008 I haven't tried that in real code, so I can't be sure, but while it may ...
- Walter Bright (5/17) Sep 03 2008 I disagree, I think just the reverse. The S(args) syntax means that it's...
- bobef (2/21) Sep 03 2008 And why not "new S(args)" to call the constructor (which is natural so f...
- Robert Fraser (11/32) Sep 03 2008 How would you distinguish between allocating the struct on the heap and
- Bill Baxter (8/15) Sep 03 2008 Except for scope of course:
- Tomas Lindquist Olsen (29/48) Sep 04 2008 This is one of those things I really dislike about D :(
- Denis Koroskin (12/64) Sep 04 2008 It may have problems with the q{}:
- Tomas Lindquist Olsen (4/18) Sep 04 2008 A valid point, I can think of lots of other ways to provide this specifi...
- Jarrett Billingsley (6/67) Sep 04 2008 auto foo = q { t: 3.1415f}; // typeof(foo) == q
- Tomas Lindquist Olsen (4/74) Sep 04 2008 I kinda like
- Russell Lewis (7/9) Sep 06 2008 They made exactly that mistake with C++'s template syntax. It is one of...
- Jarrett Billingsley (4/13) Sep 06 2008 I'll agree with that and reiterate that if we could have named
- Jarrett Billingsley (4/26) Sep 04 2008 Now were you just reading off of
- Tomas Lindquist Olsen (6/10) Sep 04 2008 Actually, I've never read that report before :P
- Bruno Medeiros (11/15) Sep 08 2008 I was reading that, and I must say, I didn't quite understand the
- Jarrett Billingsley (40/52) Sep 08 2008 Do you mean you don't understand the need for named function
- Jarrett Billingsley (40/52) Sep 08 2008 Do you mean you don't understand the need for named function
- Bruno Medeiros (12/79) Sep 12 2008 Ah, I understand now what you meant, I had forgotten about that D
- bearophile (5/7) Sep 12 2008 If you use an IDE, it tells shows you the signature of the function/meth...
- Walter Bright (3/15) Sep 04 2008 The static struct initializers more or less are inherited from C. I'd
- Leandro Lucarella (11/25) Sep 04 2008 But they are much more flexible than constructor, it's like a constructo...
- Jarrett Billingsley (5/23) Sep 04 2008 Ah, now there's a compromise I'd be more than willing to accept. If
- Christopher Wright (10/28) Sep 04 2008 This helps a lot with future proofing your structs.
- Jarrett Billingsley (4/24) Sep 03 2008 So uh,
- Moritz Warning (5/13) Sep 03 2008 Hi Jarrett,
- Jarrett Billingsley (4/17) Sep 03 2008 Ack, I've started using the mailing lists and gmail to interact with
- Bill Baxter (9/29) Sep 03 2008 That happened to me too.
- Jarrett Billingsley (4/35) Sep 03 2008 I think I was the one who pointed it out to you, making my
- Walter Bright (2/3) Sep 03 2008 See my reply to bearophile
- Pablo Ripolles (29/52) Sep 04 2008 shouldn't this be so only for the static opCall's?
- Pablo Ripolles (5/78) Sep 04 2008 little typo:
- Walter Bright (2/9) Sep 04 2008 That would make opCall overload unlike anything else.
- Pablo Ripolles (12/22) Sep 04 2008 Ok, sorry again, I didn't mean overloading, I did mean *override* or sub...
- Bill Baxter (8/11) Sep 04 2008 If that's really the case with the latest D2 then that is odd. In C++
- Walter Bright (2/15) Sep 04 2008 The non-static opCall should work fine.
- Bill Baxter (4/13) Sep 04 2008 Ok. Groovy then.
- Max Samukha (39/54) Sep 04 2008 Only the parameterless non-static opCall seem to work:
- Georg Wrede (6/31) Sep 04 2008 This might be fluent for the "people in the know", but for everybody
- Ary Borenszweig (7/14) Sep 03 2008 Please add this example to the docs. I first thought you'd create a
- Mosfet (9/27) Sep 03 2008 while you are talking about, sorry to ask but what is the use of this
- Extrawurst (10/17) Sep 03 2008 auto just helps writing code in a more brief and readable way. The
- Extrawurst (4/11) Sep 03 2008 And why is it that there is no default ctor allowed for structs ?
- Walter Bright (9/10) Sep 03 2008 Good question. Because:
- Max Samukha (32/37) Sep 03 2008 Thanks! Two questions about the struct constructors:
- Walter Bright (3/54) Sep 03 2008 Yes, that's exactly how it works.
- Max Samukha (18/72) Sep 03 2008 Should it be a compile time error? The above is semantically
- Walter Bright (2/4) Sep 03 2008 I'd forgotten about that. It's a bug.
- Steven Schveighoffer (5/12) Sep 03 2008 Thanks!
- dsimcha (3/8) Sep 03 2008 What does a struct constructor in its current form make possible/easy th...
- Walter Bright (3/5) Sep 03 2008 Aside from the logical symmetry, it enables an object to be constructed
- dsimcha (3/8) Sep 03 2008 In that case, struct ctors are a nice addition, but please don't depreca...
- Sean Kelly (6/7) Sep 03 2008 Must... have... D2. :-)
- Walter Bright (2/6) Sep 03 2008 I figured you'd be seduced sooner or later!
- Chris R. Miller (3/10) Sep 03 2008 So this would make structs (in effect) classes that don't exist on the h...
- Walter Bright (2/11) Sep 03 2008 No, structs do not inherit and do not have virtual functions.
- Ary Borenszweig (5/18) Sep 03 2008 So both syntax are possible?
- Bill Baxter (7/32) Sep 03 2008 I'm pretty sure that's:
- Walter Bright (3/7) Sep 03 2008 Creates a struct instance and returns a pointer to it.
- Steven Schveighoffer (3/10) Sep 03 2008 On the heap I assume? (hope)
- Walter Bright (2/13) Sep 03 2008 S() creates it on the stack, new S() on the heap.
- Pablo Ripolles (28/51) Sep 03 2008 shouldn't this be so only for the static opCall's?
- =?UTF-8?B?IuOBruOBl+OBhOOBiyAobm9zaGlpa2EpIg==?= (16/17) Sep 03 2008 Thanks for the nice release!
- davidl (5/22) Sep 03 2008 umm, another bug ?
- bearophile (5/6) Sep 04 2008 Around there are probably 10-20 systems able to compute integer operatio...
- Moritz Warning (5/9) Sep 04 2008 I have heard that BigInt is much faster in Tango. Maybe you could do a
- bearophile (7/10) Sep 04 2008 You can try this version of mine of the benchmark:
Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zip
Sep 02 2008
Reply to Walter,Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zipbug soup!!!! :-)
Sep 02 2008
Walter Bright wrote:Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zipNice release, thanks! One nit: running "dmd" still says "Digital Mars D Compiler v1.034". -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Sep 02 2008
Matti Niemenmaa wrote:Nice release, thanks! One nit: running "dmd" still says "Digital Mars D Compiler v1.034".Fixed!
Sep 02 2008
Walter Bright wrote:Matti Niemenmaa wrote:Congrats, etc., you know! :-) An idea: On www.digitalmars.com you currently replace the Current Version link with the, ehhh, Current Version, right? Now, would it be a better idea to announce here the existence of DMD X.0xx /without/ changing the default link on the web site? Point being, you'd want to get feedback for at least a week from this NG, before "publishing to the world at large" the new version. This might be handy for "real errors", because then you could have some comment next to the link about, well, caveats or whatever. Even better, you'd get rid of the most trivial, and embarrassing, erros (of the kind I make all the time, like "says v1.034") before the regular downloaders hear of them. georg PS, think about those who don't read this NG, who just happen to download the obvious choice, the current version, and then there's some embarrassing or downright dangerous thing with it, and he never gets the wiser -- because we can't mandate that everyone reads this NG. /At least 1.xx/ should do this.Nice release, thanks! One nit: running "dmd" still says "Digital Mars D Compiler v1.034".Fixed!
Sep 04 2008
Georg Wrede wrote:/At least 1.xx/ should do this.That's why the default download is for an older version.
Sep 05 2008
Great update once again, thanks!Special member functions _ctor, _dtor, etc., now have two leading _ in order to not conflict with the user identifier space.Ow, just rename this/~this to ctor/dtor and get it over with! :O L.
Sep 02 2008
Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice. nice release though. thanks for the bugfixing! Walter Bright wrote:Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zip
Sep 03 2008
To construct an object of struct S: auto s = S(arguments); Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
yeah i figured, but if i have an opCall with the exact same arguments its never called, isnt that ambiguous ? what happens to opcall anyway ? will it sooner or later fall out ? Walter Bright wrote:To construct an object of struct S: auto s = S(arguments); Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
Extrawurst wrote:yeah i figured, but if i have an opCall with the exact same arguments its never called, isnt that ambiguous ? what happens to opcall anyway ? will it sooner or later fall out ? Walter Bright wrote:ctor's override the opCalls. The opCalls will eventually probably get deprecated.To construct an object of struct S: auto s = S(arguments); Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
Walter Bright wrote:Extrawurst wrote:Well the advandage of opCall is (in my intention) that you can have an empty argument list. it think its kind of inconsistend if u want to do reference counting in a generic struct template, isnt it ?yeah i figured, but if i have an opCall with the exact same arguments its never called, isnt that ambiguous ? what happens to opcall anyway ? will it sooner or later fall out ? Walter Bright wrote:ctor's override the opCalls. The opCalls will eventually probably get deprecated.To construct an object of struct S: auto s = S(arguments); Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
Walter Bright Wrote:Extrawurst wrote:opCalls are much more flexible than ctor's because their return type may vary or they may not have return type. I vote against deprecating them. Let whoever likes ctors use them and whoever likes opCalls use these. Regardsyeah i figured, but if i have an opCall with the exact same arguments its never called, isnt that ambiguous ? what happens to opcall anyway ? will it sooner or later fall out ? Walter Bright wrote:ctor's override the opCalls. The opCalls will eventually probably get deprecated.To construct an object of struct S: auto s = S(arguments); Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
bobef wrote:opCalls are much more flexible than ctor's because their return type may vary or they may not have return type. I vote against deprecating them. Let whoever likes ctors use them and whoever likes opCalls use these.I agree opCalls are more flexible, but unfortunately you can't have both because of syntactical ambiguity... :-( regards, 0ffh
Sep 03 2008
Content-Disposition: inline On Wed, Sep 3, 2008 at 4:30 PM, 0ffh <frank youknow.what.todo.internetz>wrote:bobef wrote:Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).opCalls are much more flexible than ctor's because their return type may vary or they may not have return type. I vote against deprecating them. Let whoever likes ctors use them and whoever likes opCalls use these.I agree opCalls are more flexible, but unfortunately you can't have both because of syntactical ambiguity... :-( regards, 0ffh
Sep 03 2008
Jarrett Billingsley wrote:Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.
Sep 03 2008
Walter Bright:If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals... Bye, bearophile
Sep 03 2008
bearophile wrote:Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 03 2008
Walter Bright Wrote:bearophile wrote:And why not "new S(args)" to call the constructor (which is natural so far) and "S(args)" to work as it does now?Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 03 2008
bobef wrote:Walter Bright Wrote:How would you distinguish between allocating the struct on the heap and on the stack? "new" anything does heap allocation and returns a pointer/reference, so it would be inconsistent if it did stack allocation for structs (plus, then you'd have to manually allocate the heap memory & copy the struct over... ew). class C { } struct S { } int* i = new int; // Heap allocates C c = new C; // Heap allocates S* s = new S; // Heap allocatesbearophile wrote:And why not "new S(args)" to call the constructor (which is natural so far) and "S(args)" to work as it does now?Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 03 2008
On Thu, Sep 4, 2008 at 2:21 PM, Robert Fraser <fraserofthenight gmail.com> wrote:Except for scope of course: scope foo = new Foo(); But I would guess for consistency that scope sfoo = new StructFoo(); should return a pointer to a stack-allocated struct. --bbAnd why not "new S(args)" to call the constructor (which is natural so far) and "S(args)" to work as it does now?How would you distinguish between allocating the struct on the heap and on the stack? "new" anything does heap allocation and returns a pointer/reference, so it would be inconsistent if it did stack allocation for structs
Sep 03 2008
Walter Bright wrote:bearophile wrote:This is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name? struct S { int a; float b; } const s = S{1, 2.0}; const t = S{b:3.14}; void foo() { auto st = S{4,5.5}; } (also not that it's currently impossible to use type inference with the current static struct initializers) This would eliminate the gripe most people have with this I think, as well as making static and non-static initializers consistent. like they are *for all other types*. I can't help feel structs (like static arrays) aren't first class citizens in D. Even with the latest additions in D2. It hurts, and is just one of those small reasons why I sometimes regret I even joined this community... My 2 cents on this, I think it's a big mistake going against the wishes of the D community. If I'm wrong, let me know. -TomasWalter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 04 2008
On Thu, 04 Sep 2008 15:44:30 +0400, Tomas Lindquist Olsen <tomas famolsen.dk> wrote:Walter Bright wrote:It may have problems with the q{}: struct q { float t; } auto foo = q{ t = 3.1415f }; // what's the type of foo? But then, does anybody using it? Other than that I agree, current solution is not very good.bearophile wrote:This is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name? struct S { int a; float b; } const s = S{1, 2.0}; const t = S{b:3.14}; void foo() { auto st = S{4,5.5}; }Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...(also not that it's currently impossible to use type inference with the current static struct initializers) This would eliminate the gripe most people have with this I think, as well as making static and non-static initializers consistent. like they are *for all other types*. I can't help feel structs (like static arrays) aren't first class citizens in D. Even with the latest additions in D2. It hurts, and is just one of those small reasons why I sometimes regret I even joined this community... My 2 cents on this, I think it's a big mistake going against the wishes of the D community. If I'm wrong, let me know. -Tomas-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Sep 04 2008
Denis Koroskin wrote:It may have problems with the q{}: struct q { float t; } auto foo = q{ t = 3.1415f }; // what's the type of foo? But then, does anybody using it? Other than that I agree, current solution is not very good.A valid point, I can think of lots of other ways to provide this specific feature though. I'd also guess that struct literals are much more common than tokenized strings... So... I don't think this is a valid reason to dismiss this!
Sep 04 2008
On Thu, Sep 4, 2008 at 7:58 AM, Denis Koroskin <2korden gmail.com> wrote:On Thu, 04 Sep 2008 15:44:30 +0400, Tomas Lindquist Olsen <tomas famolsen.dk> wrote:auto foo = q { t: 3.1415f}; // typeof(foo) == q q{ is treated more or less as an atomic character. Put a space between them and bam, you have a struct literal. And please don't get rid of token strings; those of us who love mixins wouldn't want to see them go ;)Walter Bright wrote:It may have problems with the q{}: struct q { float t; } auto foo = q{ t = 3.1415f }; // what's the type of foo? But then, does anybody using it? Other than that I agree, current solution is not very good.bearophile wrote:This is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name? struct S { int a; float b; } const s = S{1, 2.0}; const t = S{b:3.14}; void foo() { auto st = S{4,5.5}; }Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 04 2008
Jarrett Billingsley wrote:On Thu, Sep 4, 2008 at 7:58 AM, Denis Koroskin <2korden gmail.com> wrote:I kinda like ""{foobar etc} as an alternativeOn Thu, 04 Sep 2008 15:44:30 +0400, Tomas Lindquist Olsen <tomas famolsen.dk> wrote:auto foo = q { t: 3.1415f}; // typeof(foo) == q q{ is treated more or less as an atomic character. Put a space between them and bam, you have a struct literal. And please don't get rid of token strings; those of us who love mixins wouldn't want to see them go ;)Walter Bright wrote:It may have problems with the q{}: struct q { float t; } auto foo = q{ t = 3.1415f }; // what's the type of foo? But then, does anybody using it? Other than that I agree, current solution is not very good.bearophile wrote:This is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name? struct S { int a; float b; } const s = S{1, 2.0}; const t = S{b:3.14}; void foo() { auto st = S{4,5.5}; }Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 04 2008
Jarrett Billingsley wrote:q{ is treated more or less as an atomic character. Put a space between them and bam, you have a struct literal.They made exactly that mistake with C++'s template syntax. It is one of the reasons that D's template syntax is better. It's an idea that sounds good when you are looking at it from an abstract, "yeah we could parse that" direction, but it makes for unreadable (and unwritable) code with strange syntax errors that are hard to find.
Sep 06 2008
On Sat, Sep 6, 2008 at 8:38 AM, Russell Lewis <webmaster villagersonline.com> wrote:Jarrett Billingsley wrote:I'll agree with that and reiterate that if we could have named parameters I could care less about having better struct literals.q{ is treated more or less as an atomic character. Put a space between them and bam, you have a struct literal.They made exactly that mistake with C++'s template syntax. It is one of the reasons that D's template syntax is better. It's an idea that sounds good when you are looking at it from an abstract, "yeah we could parse that" direction, but it makes for unreadable (and unwritable) code with strange syntax errors that are hard to find.
Sep 06 2008
On Thu, Sep 4, 2008 at 7:44 AM, Tomas Lindquist Olsen <tomas famolsen.dk> wrote:The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name? struct S { int a; float b; } const s = S{1, 2.0}; const t = S{b:3.14}; void foo() { auto st = S{4,5.5}; } (also not that it's currently impossible to use type inference with the current static struct initializers) This would eliminate the gripe most people have with this I think, as well as making static and non-static initializers consistent. like they are *for all other types*.Now were you just reading off of http://d.puremagic.com/issues/show_bug.cgi?id=2170 or did you come to this conclusion independently ;)
Sep 04 2008
Jarrett Billingsley wrote:Now were you just reading off of http://d.puremagic.com/issues/show_bug.cgi?id=2170 or did you come to this conclusion independently ;)Actually, I've never read that report before :P Seriously !! But it looks like we pretty much agree ... Glad I'm not alone here ;) -Tomas
Sep 04 2008
Jarrett Billingsley wrote:Now were you just reading off of http://d.puremagic.com/issues/show_bug.cgi?id=2170 or did you come to this conclusion independently ;)I was reading that, and I must say, I didn't quite understand the reasoning behind that named function parameters proposal. And what do you mean with "The issue with this is that you have to have a different named struct for every function that takes this style of parameters" ? Were you suggesting that functions who want to receive named parameters should declare an arguments struct just for that? -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Sep 08 2008
On Mon, Sep 8, 2008 at 9:39 AM, Bruno Medeiros <brunodomedeiros+spam com.gmail> wrote:Jarrett Billingsley wrote:Do you mean you don't understand the need for named function parameters, or you're not clear on the mechanism? If the former, named parameters are just a clearer way of calling functions that take a lot of parameters or a lot of potentially confusing parameters. If the latter, D currently allows you to do something like this: class A { this(int, int, int){} } void foo(A a...) { // a is a reference to a new instance of A } foo(1, 2, 3); // same as foo(new A(1, 2, 3)); So my idea is, if struct literals allow for named members, it's not much of a step to go from foo(SomeStruct{x: 1, y: 2}) to: foo(x: 1, y: 2)Now were you just reading off of http://d.puremagic.com/issues/show_bug.cgi?id=2170 or did you come to this conclusion independently ;)I was reading that, and I must say, I didn't quite understand the reasoning behind that named function parameters proposal.And what do you mean with "The issue with this is that you have to have a different named struct for every function that takes this style of parameters" ? Were you suggesting that functions who want to receive named parameters should declare an arguments struct just for that?Yes. Although without the syntactic sugar, you'd end up having to write i.e. foo(FooArgs{x: 1, y: 2}) bar(BarArgs{z: 3.4, w: "hi"}) hence having to repeat the name of the function once for the function itself and again for the named arguments. With sugar, the argument structure name and braces go away, but it still doesn't solve the problem of having to declare an argument structure for every function. But, if we were to get named parameters for all functions, then both problems are solved: you have named parameters for free functions and methods, and you can initialize structs that have constructors or static opCalls with named members instead of having to write them in order: struct S { int x, y, z; this(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } S(1, 2, 3) and S(x: 1, y: 2, z: 3) are now both legal.
Sep 08 2008
On Mon, Sep 8, 2008 at 9:39 AM, Bruno Medeiros <brunodomedeiros+spam com.gmail> wrote:Jarrett Billingsley wrote:Do you mean you don't understand the need for named function parameters, or you're not clear on the mechanism? If the former, named parameters are just a clearer way of calling functions that take a lot of parameters or a lot of potentially confusing parameters. If the latter, D currently allows you to do something like this: class A { this(int, int, int){} } void foo(A a...) { // a is a reference to a new instance of A } foo(1, 2, 3); // same as foo(new A(1, 2, 3)); So my idea is, if struct literals allow for named members, it's not much of a step to go from foo(SomeStruct{x: 1, y: 2}) to: foo(x: 1, y: 2)Now were you just reading off of http://d.puremagic.com/issues/show_bug.cgi?id=2170 or did you come to this conclusion independently ;)I was reading that, and I must say, I didn't quite understand the reasoning behind that named function parameters proposal.And what do you mean with "The issue with this is that you have to have a different named struct for every function that takes this style of parameters" ? Were you suggesting that functions who want to receive named parameters should declare an arguments struct just for that?Yes. Although without the syntactic sugar, you'd end up having to write i.e. foo(FooArgs{x: 1, y: 2}) bar(BarArgs{z: 3.4, w: "hi"}) hence having to repeat the name of the function once for the function itself and again for the named arguments. With sugar, the argument structure name and braces go away, but it still doesn't solve the problem of having to declare an argument structure for every function. But, if we were to get named parameters for all functions, then both problems are solved: you have named parameters for free functions and methods, and you can initialize structs that have constructors or static opCalls with named members instead of having to write them in order: struct S { int x, y, z; this(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } S(1, 2, 3) and S(x: 1, y: 2, z: 3) are now both legal.
Sep 08 2008
Jarrett Billingsley wrote:On Mon, Sep 8, 2008 at 9:39 AM, Bruno Medeiros <brunodomedeiros+spam com.gmail> wrote:I meant the mechanismJarrett Billingsley wrote:Do you mean you don't understand the need for named function parameters, or you're not clear on the mechanism?Now were you just reading off of http://d.puremagic.com/issues/show_bug.cgi?id=2170 or did you come to this conclusion independently ;)I was reading that, and I must say, I didn't quite understand the reasoning behind that named function parameters proposal.If the former, named parameters are just a clearer way of calling functions that take a lot of parameters or a lot of potentially confusing parameters. If the latter, D currently allows you to do something like this: class A { this(int, int, int){} } void foo(A a...) { // a is a reference to a new instance of A } foo(1, 2, 3); // same as foo(new A(1, 2, 3)); So my idea is, if struct literals allow for named members, it's not much of a step to go from foo(SomeStruct{x: 1, y: 2}) to: foo(x: 1, y: 2)Ah, I understand now what you meant, I had forgotten about that D feature that would implicitly call the constructor on a function call.Yeah, which still makes it un-useful in my opinion.And what do you mean with "The issue with this is that you have to have a different named struct for every function that takes this style of parameters" ? Were you suggesting that functions who want to receive named parameters should declare an arguments struct just for that?Yes. Although without the syntactic sugar, you'd end up having to write i.e. foo(FooArgs{x: 1, y: 2}) bar(BarArgs{z: 3.4, w: "hi"}) hence having to repeat the name of the function once for the function itself and again for the named arguments. With sugar, the argument structure name and braces go away, but it still doesn't solve the problem of having to declare an argument structure for every function.But, if we were to get named parameters for all functions, then both problems are solved: you have named parameters for free functions and methods, and you can initialize structs that have constructors or static opCalls with named members instead of having to write them in order: struct S { int x, y, z; this(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } S(1, 2, 3) and S(x: 1, y: 2, z: 3) are now both legal.Now this would be a proper design for the named parameters feature. But still, to say the truth, it's not something I miss much. I understand it's use case, but I've never felt much need for it in any of the languages I've programmed. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Sep 12 2008
Bruno Medeiros:it's not something I miss much. I understand it's use case, but I've never felt much need for it in any of the languages I've programmed.If you use an IDE, it tells shows you the signature of the function/method, so such feature is less useful. But if you don't use an IDE, or you are using a dynamic language (where for the IDE is less easy to give help), they become quite useful, especially when you have several arguments, and several of them have a default value. So it's a form of documentation of the code, helps avoid some bugs, reduced the need to remember the exact signature if you don't have an IDE, etc. As most things if you overdo it, it may give you problems... Note that for delegates/closures named arguments may give some problems, because you don't know at compile time what is the order of the arguments. To solve this problem in ShedSkin I have added an extra hidden uint or ulong argument to those closures, used as a bitmask of 32 or 64 bits, to tell the closure what are the arguments actually passed... :-) If you want more details I can explain. If there are more than 64 arguments you can add a second uint or ulong, etc. Bye, bearophile
Sep 12 2008
Tomas Lindquist Olsen wrote:This is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name?The static struct initializers more or less are inherited from C. I'd eventually like to abandon them and go completely to the S(args) syntax.
Sep 04 2008
Walter Bright, el 4 de septiembre a las 10:26 me escribiste:Tomas Lindquist Olsen wrote:But they are much more flexible than constructor, it's like a constructor with named arguments! =) If you add support to named arguments, then I'll agree ;) -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- PROTESTA EN PLAZA DE MAYO: MUSICO SE COSIO LA BOCA -- Crónica TVThis is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name?The static struct initializers more or less are inherited from C. I'd eventually like to abandon them and go completely to the S(args) syntax.
Sep 04 2008
On Thu, Sep 4, 2008 at 2:09 PM, Leandro Lucarella <llucax gmail.com> wrote:Walter Bright, el 4 de septiembre a las 10:26 me escribiste:Ah, now there's a compromise I'd be more than willing to accept. If we didn't get S{} style struct literals, but were able to do S(x: 5, y: 10), that would be just as good. Named parameters are sooo easy! Please implement them!Tomas Lindquist Olsen wrote:But they are much more flexible than constructor, it's like a constructor with named arguments! =) If you add support to named arguments, then I'll agree ;)This is one of those things I really dislike about D :( It's really nice that we can override struct initialization, but the fact that it eliminates the possibility to override it (with a nice syntax) makes it much less appealing IMHO. The most important point to me, is that old thing about static struct initializer and struct literals have different syntaxes, and that the static variant is much more flexible. I would have loved to see the static struct initializer syntax become an expression. If the problem is ambiguity, why not just prefix the {} braces with the struct name?The static struct initializers more or less are inherited from C. I'd eventually like to abandon them and go completely to the S(args) syntax.
Sep 04 2008
Walter Bright wrote:bearophile wrote:This helps a lot with future proofing your structs. I'm trying to think of a downside... It's a method call, which is a small performance hit. But it's a very small one, considering that it's a final method. It's a method call, so it could throw an exception. That's just a bug in your code, and easier to find than some random error way down the line. You might be doing something dangerous with leaving stuff on an old stack frame and still accessing it. Then you're in the realm of undefined behavior.Walter Bright:I disagree, I think just the reverse. The S(args) syntax means that it's entirely up to the struct designer to say how it should work. The user needn't know or care, and the struct designer can change the design without affecting user code.If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.I haven't tried that in real code, so I can't be sure, but while it may work for the compiler, it sounds a bit too much complex for the person that later reads the code. Too many alternative possibilities may make the code more complex to follow. To reduce such ambiguity (ambiguity for the person, not for the compiler) may be to change the syntax of struct literals...
Sep 04 2008
Content-Disposition: inline On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1 digitalmars.com>wrote:Jarrett Billingsley wrote:So uh, why don't you want to change struct literals?Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.
Sep 03 2008
On Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1 digitalmars.com>wrote:Hi Jarrett, do you mind not to use html markup? My news reader has no html renderer, nor my eye to brain connection. Thanks. :)Jarrett Billingsley wrote:literals?<br><br></div>
Sep 03 2008
On Wed, Sep 3, 2008 at 8:22 PM, Moritz Warning <moritzwarning web.de> wrote:On Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:Ack, I've started using the mailing lists and gmail to interact with the newsgroups and forgot that it uses HTML by default, thanks for the heads up.On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1 digitalmars.com>wrote:Hi Jarrett, do you mind not to use html markup? My news reader has no html renderer, nor my eye to brain connection. Thanks. :)Jarrett Billingsley wrote:literals?<br><br></div>
Sep 03 2008
On Thu, Sep 4, 2008 at 10:38 AM, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:On Wed, Sep 3, 2008 at 8:22 PM, Moritz Warning <moritzwarning web.de> wrote:That happened to me too. I posted a suggestion to Google after that that Gmail should be smart enough not to reply to a plain text message with an HTML formatted one. Or that there should be a way to specify certain recipients don't get HTML. Maybe if you suggest it too it will push it up on their radar a bit. --bbOn Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:Ack, I've started using the mailing lists and gmail to interact with the newsgroups and forgot that it uses HTML by default, thanks for the heads up.On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1 digitalmars.com>wrote:Hi Jarrett, do you mind not to use html markup? My news reader has no html renderer, nor my eye to brain connection. Thanks. :)Jarrett Billingsley wrote:literals?<br><br></div>
Sep 03 2008
On Wed, Sep 3, 2008 at 9:47 PM, Bill Baxter <wbaxter gmail.com> wrote:On Thu, Sep 4, 2008 at 10:38 AM, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:I think I was the one who pointed it out to you, making my transgression more than inexcusable ;) I'll let them know.On Wed, Sep 3, 2008 at 8:22 PM, Moritz Warning <moritzwarning web.de> wrote:That happened to me too. I posted a suggestion to Google after that that Gmail should be smart enough not to reply to a plain text message with an HTML formatted one. Or that there should be a way to specify certain recipients don't get HTML. Maybe if you suggest it too it will push it up on their radar a bit. --bbOn Wed, 03 Sep 2008 20:04:49 -0400, Jarrett Billingsley wrote:Ack, I've started using the mailing lists and gmail to interact with the newsgroups and forgot that it uses HTML by default, thanks for the heads up.On Wed, Sep 3, 2008 at 7:29 PM, Walter Bright <newshound1 digitalmars.com>wrote:Hi Jarrett, do you mind not to use html markup? My news reader has no html renderer, nor my eye to brain connection. Thanks. :)Jarrett Billingsley wrote:literals?<br><br></div>
Sep 03 2008
Jarrett Billingsley wrote:why don't you want to change struct literals?See my reply to bearophile
Sep 03 2008
Sorry, but this is already somewhere else, I don't know why but I get my responses out of thread... Walter Bright Wrote:Jarrett Billingsley wrote:shouldn't this be so only for the static opCall's? shouldn't this be possible? /////////////////////////////////////////////////////// import std.stdio; struct Parabola { float a_; this(float a) { a_ = a; } float opCall(float x) { return a_ * x*x; } } void main() { Parabola f; float x, y; f = Parabola(1.0); x = 2.0; y = f(x); writefln("f(%1$s) = %2$%", x, y); } /////////////////////////////////////////////////////// Thanks!Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call.Otherwise, it's a struct literal.
Sep 04 2008
little typo: writefln("f(%1$s) = %2$%", x, y); ---> writefln("f(%1$s) = %2$s", x, y); it doesn't compile anyway! Walter, don't you think that the ctor overloading should be on "static opCall" better than *any* opCall? Pablo Ripolles Wrote:Sorry, but this is already somewhere else, I don't know why but I get my responses out of thread... Walter Bright Wrote:Jarrett Billingsley wrote:shouldn't this be so only for the static opCall's? shouldn't this be possible? /////////////////////////////////////////////////////// import std.stdio; struct Parabola { float a_; this(float a) { a_ = a; } float opCall(float x) { return a_ * x*x; } } void main() { Parabola f; float x, y; f = Parabola(1.0); x = 2.0; y = f(x); writefln("f(%1$s) = %2$%", x, y); } /////////////////////////////////////////////////////// Thanks!Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call.Otherwise, it's a struct literal.
Sep 04 2008
Pablo Ripolles wrote:little typo: writefln("f(%1$s) = %2$%", x, y); ---> writefln("f(%1$s) = %2$s", x, y); it doesn't compile anyway! Walter, don't you think that the ctor overloading should be on "static opCall" better than *any* opCall?That would make opCall overload unlike anything else.
Sep 04 2008
Walter Bright Wrote:Pablo Ripolles wrote:Ok, sorry again, I didn't mean overloading, I did mean *override* or substitute as there is no inheritance for the structs. does it change your answer? Walter, please, correct me where I'm wrong. * ctors are somehow static operations (UML parlance), they construct the instance when the struct identifier is invoked with the corresponding arguments through the "()" operator. * static ctors, being the keyword "static" not an "Attribute" but a "StorageClass" (in D parlance), are something different. * static member functions, being the keyword "static" an "Attribute" (in D parlance), are static operations (UML parlance) as they don't need an instance to be invoked on. * opCall is the member function that is invoked when the calling-function-operator "()" is applied to an instance as if it were a function * static opCall is the static member function that is invoked when the calling-function-operator "()" is applied to a struct identifier as if it were a function. Hence, since there is a clear connection between the first point and the last point, why should the ctor substitute (or *override* as it has been used by you before) other than the static opCall mentioned in the last point? My experiments with real code and the last compiler version show that once there is present a ctor it even invalidates the possibility of accessing the *non-static* opCall to use a plain instance of that struct as if it were a function. Is that the expected behavior? I would understand if that the preference would take place between the ctor and the static opCall (both use the same syntactic expression on the struct), but I sincerely don't see the symmetry when the preference takes place between the ctor and the non-static opCall. Thanks!little typo: writefln("f(%1$s) = %2$%", x, y); ---> writefln("f(%1$s) = %2$s", x, y); it doesn't compile anyway! Walter, don't you think that the ctor overloading should be on "static opCall" better than *any* opCall?That would make opCall overload unlike anything else.
Sep 04 2008
On Fri, Sep 5, 2008 at 6:20 AM, Pablo Ripolles <in-call gmx.net> wrote:Walter Bright Wrote: Hence, since there is a clear connection between the first point and the last point, why should the ctor substitute (or *override* as it has been used by you before) other than the static opCall mentioned in the last point? My experiments with real code and the last compiler version show that once there is present a ctor it even invalidates the possibility of accessing the *non-static* opCall to use a plain instance of that struct as if it were a function. Is that the expected behavior?If that's really the case with the latest D2 then that is odd. In C++ there isn't even a static opCall, only the non-static variety, but it works just fine in conjunction with constructors. Functor structs and structs with constructors should not be mutually exclusive. Kill off static opCall, fine, but don't kill instance opCall. That's one step forward one step back. --bb
Sep 04 2008
Bill Baxter wrote:On Fri, Sep 5, 2008 at 6:20 AM, Pablo Ripolles <in-call gmx.net> wrote:The non-static opCall should work fine.Walter Bright Wrote: Hence, since there is a clear connection between the first point and the last point, why should the ctor substitute (or *override* as it has been used by you before) other than the static opCall mentioned in the last point? My experiments with real code and the last compiler version show that once there is present a ctor it even invalidates the possibility of accessing the *non-static* opCall to use a plain instance of that struct as if it were a function. Is that the expected behavior?If that's really the case with the latest D2 then that is odd. In C++ there isn't even a static opCall, only the non-static variety, but it works just fine in conjunction with constructors. Functor structs and structs with constructors should not be mutually exclusive. Kill off static opCall, fine, but don't kill instance opCall. That's one step forward one step back.
Sep 04 2008
On Fri, Sep 5, 2008 at 6:37 AM, Walter Bright <newshound1 digitalmars.com> wrote:Bill Baxter wrote:Ok. Groovy then. --bbIf that's really the case with the latest D2 then that is odd. In C++ there isn't even a static opCall, only the non-static variety, but it works just fine in conjunction with constructors. Functor structs and structs with constructors should not be mutually exclusive. Kill off static opCall, fine, but don't kill instance opCall. That's one step forward one step back.The non-static opCall should work fine.
Sep 04 2008
On Thu, 04 Sep 2008 14:37:27 -0700, Walter Bright <newshound1 digitalmars.com> wrote:Bill Baxter wrote:Only the parameterless non-static opCall seem to work: struct S { this(int x) { } void opCall() { } } auto s = S(1); s(); // ok In other cases the compiler ignores the opCall and tries to use the constructor: struct S { this(int x) { } void opCall(int y) { } } auto s = S(1); s(1); // Error: * has no effect in expression Also, when opCall is a better match: struct S { this(int x) { } void opCall(int y, int z) { } } auto s = S(1); s(1, 2); // Error: this(int x) does not match parameter typesOn Fri, Sep 5, 2008 at 6:20 AM, Pablo Ripolles <in-call gmx.net> wrote:The non-static opCall should work fine.Walter Bright Wrote: Hence, since there is a clear connection between the first point and the last point, why should the ctor substitute (or *override* as it has been used by you before) other than the static opCall mentioned in the last point? My experiments with real code and the last compiler version show that once there is present a ctor it even invalidates the possibility of accessing the *non-static* opCall to use a plain instance of that struct as if it were a function. Is that the expected behavior?If that's really the case with the latest D2 then that is odd. In C++ there isn't even a static opCall, only the non-static variety, but it works just fine in conjunction with constructors. Functor structs and structs with constructors should not be mutually exclusive. Kill off static opCall, fine, but don't kill instance opCall. That's one step forward one step back.
Sep 04 2008
Walter Bright wrote:Jarrett Billingsley wrote:This might be fluent for the "people in the know", but for everybody else (which is /everybody else/, until they become "people in the know") it is just distracting, ambiguous, and prone to misinterpretation. And this simply makes it take more time when debuggin the works of your team. Something ought to be done here.Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call. Otherwise, it's a struct literal.
Sep 04 2008
Walter Bright a crit :To construct an object of struct S: auto s = S(arguments);Please add this example to the docs. I first thought you'd create a struct like auto s = new S(arguments); (so that constructing something has a consistent syntax... so if then you decide to change your struct to a class, or viceversa, and you don't have to change a lot of bits everywhere)Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
Ary Borenszweig wrote:Walter Bright a crit :while you are talking about, sorry to ask but what is the use of this keyword ? When I look at documentation I can read : The auto attribute is used when there are no other attributes and type inference is desired. In which case you want inference type ? Is it a kind o C++ RTTI ? In the sample code above, you already know that struct is of kind S. First I thought auto means automatically destruct object when out of scope.To construct an object of struct S: auto s = S(arguments);Please add this example to the docs. I first thought you'd create a struct like auto s = new S(arguments); (so that constructing something has a consistent syntax... so if then you decide to change your struct to a class, or viceversa, and you don't have to change a lot of bits everywhere)Extrawurst wrote:Are opCalls deprecated now ? how do i call the ctor and how the opCall? a short example in the docs would have been nice.
Sep 03 2008
Mosfet wrote:When I look at documentation I can read : The auto attribute is used when there are no other attributes and type inference is desired. In which case you want inference type ? Is it a kind o C++ RTTI ? In the sample code above, you already know that struct is of kind S. First I thought auto means automatically destruct object when out of scope.auto just helps writing code in a more brief and readable way. The compiler infers the type which u are using by the right side of the expression, which is extremly handy when u use cascaded templates a lot. example: MyTemplateA!(MyTemplateB("foo")) variablename = new MyTemplateA!(MyTemplateB("foo"))("aParemterString"); with auto u just have to write it once: auto variablename = new MyTemplateA!(MyTemplateB("foo"))("aParemterString"); the compiler infers the type of variablename looking at the expression.
Sep 03 2008
And why is it that there is no default ctor allowed for structs ? struct S{this(){}} //constructor main.S.this default constructor not allowed for structs Walter Bright wrote:Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zip
Sep 03 2008
Extrawurst wrote:And why is it that there is no default ctor allowed for structs ?Good question. Because: 1. Having a default ctor conflicts with the concept of a .init property. 2. Using .init for default construction guarantees it can never throw, which is a useful property in many generic programming circumstances 3. It guarantees it is pure. 4. Nearly every instance of default construction I've seen would initialize it just to what .init does in D. 5. It eliminates the need for a member initializer syntax.
Sep 03 2008
On Tue, 02 Sep 2008 22:42:06 -0700, Walter Bright <newshound1 digitalmars.com> wrote:Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zipThanks! Two questions about the struct constructors: 1. Why is there the limitation that the constructor list may not be empty? One problem with that rule is incorrect handling of a single parameter with a default value: struct S { this(int x = 1) { writefln("Ctor"); } } S s = S(); The constructor is not called. Is such a parameter list considered empty or non-empty? 2. How do constructiors affect static opCalls? struct S { this(int x) { } static void opCall(int x, int y) { } } S s; s(1, 2); Error: constructor Test.main.S.this (int x) does not match parameter types (int,int) dmd seems to ignore static opCalls completely, if there is a constructor. Is it intended behavior?
Sep 03 2008
Max Samukha wrote:On Tue, 02 Sep 2008 22:42:06 -0700, Walter Bright <newshound1 digitalmars.com> wrote:Empty.Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zipThanks! Two questions about the struct constructors: 1. Why is there the limitation that the constructor list may not be empty? One problem with that rule is incorrect handling of a single parameter with a default value: struct S { this(int x = 1) { writefln("Ctor"); } } S s = S(); The constructor is not called. Is such a parameter list considered empty or non-empty?2. How do constructiors affect static opCalls? struct S { this(int x) { } static void opCall(int x, int y) { } } S s; s(1, 2); Error: constructor Test.main.S.this (int x) does not match parameter types (int,int) dmd seems to ignore static opCalls completely, if there is a constructor. Is it intended behavior?Yes, that's exactly how it works.
Sep 03 2008
On Wed, 03 Sep 2008 00:57:40 -0700, Walter Bright <newshound1 digitalmars.com> wrote:Max Samukha wrote:Should it be a compile time error? The above is semantically equivalent to struct S { this() { this(1); } this(int x) { } } which is not allowed. Incidentally, calling other constructors from a constructor doesn't work. Is it a bug?On Tue, 02 Sep 2008 22:42:06 -0700, Walter Bright <newshound1 digitalmars.com> wrote:Empty.Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zipThanks! Two questions about the struct constructors: 1. Why is there the limitation that the constructor list may not be empty? One problem with that rule is incorrect handling of a single parameter with a default value: struct S { this(int x = 1) { writefln("Ctor"); } } S s = S(); The constructor is not called. Is such a parameter list considered empty or non-empty?Correction: should be "S(1, 2);". "S s;" is not needed.2. How do constructiors affect static opCalls? struct S { this(int x) { } static void opCall(int x, int y) { } } S s; s(1, 2);Error: constructor Test.main.S.this (int x) does not match parameter types (int,int) dmd seems to ignore static opCalls completely, if there is a constructor. Is it intended behavior?Yes, that's exactly how it works.
Sep 03 2008
Max Samukha wrote:Incidentally, calling other constructors from a constructor doesn't work. Is it a bug?I'd forgotten about that. It's a bug.
Sep 03 2008
Walter Bright wrote:Struct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zipThanks! Also, thanks for identifying all the bugs fixed now instead of later, it makes it much easier to track my issues :) -Steve
Sep 03 2008
== Quote from Walter Bright (newshound1 digitalmars.com)'s articleStruct constructors! http://www.digitalmars.com/d/1.0/changelog.html http://ftp.digitalmars.com/dmd.1.035.zip http://www.digitalmars.com/d/2.0/changelog.html http://ftp.digitalmars.com/dmd.2.019.zipWhat does a struct constructor in its current form make possible/easy that was awkward/impossible with opCalls?
Sep 03 2008
dsimcha wrote:What does a struct constructor in its current form make possible/easy that was awkward/impossible with opCalls?Aside from the logical symmetry, it enables an object to be constructed using operator new.
Sep 03 2008
== Quote from Walter Bright (newshound1 digitalmars.com)'s articledsimcha wrote:In that case, struct ctors are a nice addition, but please don't deprecate opCall. I personally think it's fine to just make them mutually exclusive.What does a struct constructor in its current form make possible/easy that was awkward/impossible with opCalls?Aside from the logical symmetry, it enables an object to be constructed using operator new.
Sep 03 2008
Walter Bright wrote:Struct constructors!Must... have... D2. :-) By the way, no runtime changes were required to upgrade Tango to work with this release, so Tango users can drop in the new DMD without any issues. Sean
Sep 03 2008
Sean Kelly wrote:Walter Bright wrote:I figured you'd be seduced sooner or later!Struct constructors!Must... have... D2. :-)
Sep 03 2008
Walter Bright wrote:Sean Kelly wrote:So this would make structs (in effect) classes that don't exist on the he= ap?Walter Bright wrote:=20 I figured you'd be seduced sooner or later!Struct constructors!Must... have... D2. :-)
Sep 03 2008
Chris R. Miller wrote:Walter Bright wrote:No, structs do not inherit and do not have virtual functions.Sean Kelly wrote:So this would make structs (in effect) classes that don't exist on the heap?Walter Bright wrote:I figured you'd be seduced sooner or later!Struct constructors!Must... have... D2. :-)
Sep 03 2008
Walter Bright a crit :Chris R. Miller wrote:So both syntax are possible? S(...) new S(...) for a struct with a constructor? Is that documented anywhere?Walter Bright wrote:No, structs do not inherit and do not have virtual functions.Sean Kelly wrote:So this would make structs (in effect) classes that don't exist on the heap?Walter Bright wrote:I figured you'd be seduced sooner or later!Struct constructors!Must... have... D2. :-)
Sep 03 2008
On Thu, Sep 4, 2008 at 9:50 AM, Ary Borenszweig <ary esperanto.org.ar> wrot= e:Walter Bright a =E9crit :I'm pretty sure that's: S thing =3D S(...); S* ptr =3D new S(...); So yes both syntaxes are possible, but they are not synonyms. --bbChris R. Miller wrote:So both syntax are possible? S(...) new S(...) for a struct with a constructor? Is that documented anywhere?Walter Bright wrote:No, structs do not inherit and do not have virtual functions.Sean Kelly wrote:So this would make structs (in effect) classes that don't exist on the heap?Walter Bright wrote:I figured you'd be seduced sooner or later!Struct constructors!Must... have... D2. :-)
Sep 03 2008
Ary Borenszweig wrote:So both syntax are possible? S(...)Creates a struct instancenew S(...)Creates a struct instance and returns a pointer to it.
Sep 03 2008
"Walter Bright" wroteAry Borenszweig wrote:On the heap I assume? (hope) -SteveSo both syntax are possible? S(...)Creates a struct instancenew S(...)Creates a struct instance and returns a pointer to it.
Sep 03 2008
Steven Schveighoffer wrote:"Walter Bright" wroteS() creates it on the stack, new S() on the heap.Ary Borenszweig wrote:On the heap I assume? (hope)So both syntax are possible? S(...)Creates a struct instancenew S(...)Creates a struct instance and returns a pointer to it.
Sep 03 2008
Walter Bright Wrote:Jarrett Billingsley wrote:shouldn't this be so only for the static opCall's? shouldn't this be possible? /////////////////////////////////////////////////////// import std.stdio; struct Parabola { float a_; this(float a) { a_ = a; } float opCall(float x) { return a_ * x*x; } } void main() { Parabola f; float x, y; f = Parabola(1.0); x = 2.0; y = f(x); writefln("f(%1$s) = %2$%", x, y); } /////////////////////////////////////////////////////// Thanks!Speaking of syntactical ambiguity, the expression S(1, 2, 3) can, right now, have one of three meanings: 1. A struct literal for struct S 2. A call to S's static opCall 3. An instantiation of S and a call to its ctor Even if opCall goes away, we'll still be left with the ambiguity of struct literal vs. ctor. I'd really, really like to hear Walter's view on this but he has responded neither to the thread I posted on digitalmars.D nor the bugzilla ticket (http://d.puremagic.com/issues/show_bug.cgi?id=2170).If there's any constructor defined for S, then S(args) is a constructor call. If there's any opCall defined for S, then S(args) is an opCall call.Otherwise, it's a struct literal.
Sep 03 2008
Walter Bright wrote:Struct constructors!Thanks for the nice release! I have a question. The "dynamic initialization of struct" syntax seems still using opCall. Is it going to replaced by constructors? struct S { this(int x) { writeln("ctor"); } static S opCall(int x) { writeln("opCall"); return S.init; } } void main(){ S s = 1; // prints "opCall" }
Sep 03 2008
在 Thu, 04 Sep 2008 09:23:08 +0800,のしいか (noshiika) <noshiika gmail.com> 写道:Walter Bright wrote:umm, another bug ? -- 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/Struct constructors!Thanks for the nice release! I have a question. The "dynamic initialization of struct" syntax seems still using opCall. Is it going to replaced by constructors? struct S { this(int x) { writeln("ctor"); } static S opCall(int x) { writeln("opCall"); return S.init; } } void main(){ S s = 1; // prints "opCall" }
Sep 03 2008
Walter Bright Wrote:Bugzilla 2289: Stack overflow on very large BigInt to string.<Around there are probably 10-20 systems able to compute integer operations efficiently, probably written in C, or C/asm. I have tested the performance of that D2 module and it's not good, Python runs circles around it and uses just a small fraction of the memory it uses, and GMP is something like hundreds times faster. As in the case of the regex module of the stdlib (that goes O(n*n) in too many situations), this seems a situation where it can be useful to borrow code (in C, probably) from other sources. Time ago people have told me that there are some license issues, so is the only hope to wait for someone to re-invent rounder wheels for D? (I presume Tango has a different regex module, but I don't see people backporting it to Phobos now, so I presume someone else will have to write yet another better regex module for Phobos?). Bye, bearophile
Sep 04 2008
On Thu, 04 Sep 2008 03:41:15 -0400, bearophile wrote:I have tested the performance of that D2 module and it's not good, Python runs circles around it and uses just a small fraction of the memory it uses, and GMP is something like hundreds times faster.I have heard that BigInt is much faster in Tango. Maybe you could do a quick test? About the Tango regex, it has speed problems in many cases, too. http://dsource.org/projects/tango/ticket/1119
Sep 04 2008
Moritz Warning:I have heard that BigInt is much faster in Tango. Maybe you could do a quick test?I don't use Tango, and so far I've failed to make Tangobos work well with my code.About the Tango regex, it has speed problems in many cases, too.You can try this version of mine of the benchmark: http://shootout.alioth.debian.org/debian/benchmark.php?test=regexdna&lang=gdc&id=4 You can see lines marked with slow or SLOW, you can use them to replace the faster alternatives I have found, and you can see if Tango regex too is O(n*n) in that situation. Note that in that situation all the other regex engines are linear. Bye, bearophile
Sep 04 2008