digitalmars.D.announce - Re: GoingNative 2012 to be livestreamed tomorrow - part 2
- bearophile (46/46) Feb 09 2012 Some more comments about the conference.
- Andrej Mitrovic (4/6) Feb 09 2012 I think he didn't want to go off-topic. Maybe he discusses D in
- Jacob Carlborg (14/40) Feb 09 2012 Wouldn't this be possible:
- Timon Gehr (4/68) Feb 10 2012 Unfortunately, they would point to the template constraint. But I think
- Jacob Carlborg (6/80) Feb 10 2012 We already have this for regular templates so why wouldn't it work. It's...
- Timon Gehr (5/85) Feb 10 2012 I know the spec by heart :P. But you are right, your example does the
- Timon Gehr (10/25) Feb 10 2012 __ctfeWriteln is not required (it is not a declaration, therefore it
- Artur Skawina (5/16) Feb 10 2012 I can see it work for the single template case (i've used ctfe'd functio...
- Timon Gehr (2/18) Feb 10 2012 That is how I assumed it would work.
- bearophile (5/8) Feb 10 2012 I don't like pragma(msg), it even forces a newline at the end.
- Timon Gehr (3/11) Feb 10 2012 So does __ctfeWriteln.
- bearophile (11/13) Feb 10 2012 I meant using something like this, instead of a template:
- Timon Gehr (3/16) Feb 10 2012 I agree and don't think there are any valid counter-arguments.
Some more comments about the conference. -------------------------- About "Variadic Templates are Funadic" by Andrei Alexandrescu fun talk: I have had to see it at only 1-1.1X speed, to understand the language. I can't see the laser spot in the video :-( Thank you to Walter for designing D varidic templates in a simpler way. C++11 variadic templates look too much complex and over-engineered (example: the lockstep expansion seems a bit crazy). Slide 21: I didn't know that default is OK as first switch case too :-) Even the questions&answers part of this talk was interesting enough. ------------------ About Bjarne Stroustrup and Andrew Sutton "A Concept Design for C++": Regarding this code in Slide 12: template<Number Num> Num gsqrt(Num); gsqrt(2); // fine gsqrt("Silly!"); // error: char* is not a Number In D template constraints have two (or more) different usages: 1) To just remove a template from the pool of the usable ones; 2) In other situations only one template is present, and its constraints are a way to give it some static typing. In this case I'd like better error messages. Once this patch is applied: https://github.com/D-Programming-Language/dmd/pull/692 you are able to write something like this, that isn't exceptionally nice looking, but it's useful (it's going to make Phobos code a bit more hairy, but the user is going to see some better error messages): template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) { /*...*/ } An alternative is to give an else to the template constraints, but the error message is at the bottom of the function, making it not easy to find, so I don't like this syntax: int spam(T)(T x) if (IsFoo!T || IsBar!T) { // ... } else { __ctfeWriteln("'", typeid(T), "' is not Foo or Bar."); } If Concepts are a type system for templates, then "Current template code remains valid. Constrained and "traditional" templates must interoperate" means "gradual typing", or "optional typing" (see recent Racket Scheme). Slide 37, "Concepts for the STL (N3351)": how many of them are already in Phobos? Are the missing ones needed/useful for Phobos? This is Slide 39 and 40 are quite nice: template<InputIterator Iter, Predicate<ValueType<Iter>> Pred> bool all_of(Iter first, Iter last, Pred pred); std::find_if(): template<InputIterator Iter, Predicate<ValueType<Iter>> Pred> Iter find_if(Iter first, Iter last, Pred pred); Template aliases seem nice, not to save a bit of code to avoid defining another template, but to allow deducibility as explained here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf ------------------ In the "Panel: Ask Us Anything!" why didn't Andrei comment about the experience of compile-time function execution of D :-) Later I'll discuss some bits from the talk "Clang - Defending C++ from Murphy's Million Monkeys" in the main D newsgroup because it contains some things more directly relevant for D and its compiler. Bye, bearophile
Feb 09 2012
On 2/10/12, bearophile <bearophileHUGS lycos.com> wrote:In the "Panel: Ask Us Anything!" why didn't Andrei comment about the experience of compile-time function execution of D :-)I think he didn't want to go off-topic. Maybe he discusses D in private chats with Herb & Co., but since this was a C++ Q&A it would probably be rude to talk about other languages.
Feb 09 2012
On 2012-02-10 02:47, bearophile wrote:Some more comments about the conference. -------------------------- About "Variadic Templates are Funadic" by Andrei Alexandrescu fun talk: I have had to see it at only 1-1.1X speed, to understand the language. I can't see the laser spot in the video :-( Thank you to Walter for designing D varidic templates in a simpler way. C++11 variadic templates look too much complex and over-engineered (example: the lockstep expansion seems a bit crazy). Slide 21: I didn't know that default is OK as first switch case too :-) Even the questions&answers part of this talk was interesting enough. ------------------ About Bjarne Stroustrup and Andrew Sutton "A Concept Design for C++": Regarding this code in Slide 12: template<Number Num> Num gsqrt(Num); gsqrt(2); // fine gsqrt("Silly!"); // error: char* is not a Number In D template constraints have two (or more) different usages: 1) To just remove a template from the pool of the usable ones; 2) In other situations only one template is present, and its constraints are a way to give it some static typing. In this case I'd like better error messages. Once this patch is applied: https://github.com/D-Programming-Language/dmd/pull/692 you are able to write something like this, that isn't exceptionally nice looking, but it's useful (it's going to make Phobos code a bit more hairy, but the user is going to see some better error messages): template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) { /*...*/ }Wouldn't this be possible: template IsNumberWithError(T, string file = __FILE__, int line = __LINE__) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T)) { /*...*/ } __FILE__ and __LINE__ would be picked up from the "calling" point and not the declaration point of IsNumberWithError. We already have this in some cases. -- /Jacob Carlborg
Feb 09 2012
On 02/10/2012 08:17 AM, Jacob Carlborg wrote:On 2012-02-10 02:47, bearophile wrote:Unfortunately, they would point to the template constraint. But I think it would be a quite useful enhancement to pick up __FILE__ and __LINE__ at template instantiation point for the template constraint.Some more comments about the conference. -------------------------- About "Variadic Templates are Funadic" by Andrei Alexandrescu fun talk: I have had to see it at only 1-1.1X speed, to understand the language. I can't see the laser spot in the video :-( Thank you to Walter for designing D varidic templates in a simpler way. C++11 variadic templates look too much complex and over-engineered (example: the lockstep expansion seems a bit crazy). Slide 21: I didn't know that default is OK as first switch case too :-) Even the questions&answers part of this talk was interesting enough. ------------------ About Bjarne Stroustrup and Andrew Sutton "A Concept Design for C++": Regarding this code in Slide 12: template<Number Num> Num gsqrt(Num); gsqrt(2); // fine gsqrt("Silly!"); // error: char* is not a Number In D template constraints have two (or more) different usages: 1) To just remove a template from the pool of the usable ones; 2) In other situations only one template is present, and its constraints are a way to give it some static typing. In this case I'd like better error messages. Once this patch is applied: https://github.com/D-Programming-Language/dmd/pull/692 you are able to write something like this, that isn't exceptionally nice looking, but it's useful (it's going to make Phobos code a bit more hairy, but the user is going to see some better error messages): template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) { /*...*/ }Wouldn't this be possible: template IsNumberWithError(T, string file = __FILE__, int line = __LINE__) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T)) { /*...*/ } __FILE__ and __LINE__ would be picked up from the "calling" point and not the declaration point of IsNumberWithError. We already have this in some cases.
Feb 10 2012
On 2012-02-10 13:58, Timon Gehr wrote:On 02/10/2012 08:17 AM, Jacob Carlborg wrote:We already have this for regular templates so why wouldn't it work. It's documented here: http://www.dlang.org/template.html Search for "Template Value Parameters". -- /Jacob CarlborgOn 2012-02-10 02:47, bearophile wrote:Unfortunately, they would point to the template constraint. But I think it would be a quite useful enhancement to pick up __FILE__ and __LINE__ at template instantiation point for the template constraint.Some more comments about the conference. -------------------------- About "Variadic Templates are Funadic" by Andrei Alexandrescu fun talk: I have had to see it at only 1-1.1X speed, to understand the language. I can't see the laser spot in the video :-( Thank you to Walter for designing D varidic templates in a simpler way. C++11 variadic templates look too much complex and over-engineered (example: the lockstep expansion seems a bit crazy). Slide 21: I didn't know that default is OK as first switch case too :-) Even the questions&answers part of this talk was interesting enough. ------------------ About Bjarne Stroustrup and Andrew Sutton "A Concept Design for C++": Regarding this code in Slide 12: template<Number Num> Num gsqrt(Num); gsqrt(2); // fine gsqrt("Silly!"); // error: char* is not a Number In D template constraints have two (or more) different usages: 1) To just remove a template from the pool of the usable ones; 2) In other situations only one template is present, and its constraints are a way to give it some static typing. In this case I'd like better error messages. Once this patch is applied: https://github.com/D-Programming-Language/dmd/pull/692 you are able to write something like this, that isn't exceptionally nice looking, but it's useful (it's going to make Phobos code a bit more hairy, but the user is going to see some better error messages): template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) { /*...*/ }Wouldn't this be possible: template IsNumberWithError(T, string file = __FILE__, int line = __LINE__) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T)) { /*...*/ } __FILE__ and __LINE__ would be picked up from the "calling" point and not the declaration point of IsNumberWithError. We already have this in some cases.
Feb 10 2012
On 02/10/2012 02:44 PM, Jacob Carlborg wrote:On 2012-02-10 13:58, Timon Gehr wrote:I know the spec by heart :P. But you are right, your example does the same thing as bearophile's. I did not read his post carefully enough, I assumed he wanted the error message point to instantiation side of the constrained template.On 02/10/2012 08:17 AM, Jacob Carlborg wrote:We already have this for regular templates so why wouldn't it work. It's documented here: http://www.dlang.org/template.html Search for "Template Value Parameters".On 2012-02-10 02:47, bearophile wrote:Unfortunately, they would point to the template constraint. But I think it would be a quite useful enhancement to pick up __FILE__ and __LINE__ at template instantiation point for the template constraint.Some more comments about the conference. -------------------------- About "Variadic Templates are Funadic" by Andrei Alexandrescu fun talk: I have had to see it at only 1-1.1X speed, to understand the language. I can't see the laser spot in the video :-( Thank you to Walter for designing D varidic templates in a simpler way. C++11 variadic templates look too much complex and over-engineered (example: the lockstep expansion seems a bit crazy). Slide 21: I didn't know that default is OK as first switch case too :-) Even the questions&answers part of this talk was interesting enough. ------------------ About Bjarne Stroustrup and Andrew Sutton "A Concept Design for C++": Regarding this code in Slide 12: template<Number Num> Num gsqrt(Num); gsqrt(2); // fine gsqrt("Silly!"); // error: char* is not a Number In D template constraints have two (or more) different usages: 1) To just remove a template from the pool of the usable ones; 2) In other situations only one template is present, and its constraints are a way to give it some static typing. In this case I'd like better error messages. Once this patch is applied: https://github.com/D-Programming-Language/dmd/pull/692 you are able to write something like this, that isn't exceptionally nice looking, but it's useful (it's going to make Phobos code a bit more hairy, but the user is going to see some better error messages): template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) { /*...*/ }Wouldn't this be possible: template IsNumberWithError(T, string file = __FILE__, int line = __LINE__) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T)) { /*...*/ } __FILE__ and __LINE__ would be picked up from the "calling" point and not the declaration point of IsNumberWithError. We already have this in some cases.
Feb 10 2012
On 02/10/2012 02:47 AM, bearophile wrote:Once this patch is applied: https://github.com/D-Programming-Language/dmd/pull/692 you are able to write something like this, that isn't exceptionally nice looking, but it's useful (it's going to make Phobos code a bit more hairy, but the user is going to see some better error messages): template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); } double gsqrt(T)(T x) if (IsNumberWithError!(T, __FILE__, __LINE__)) { /*...*/ }__ctfeWriteln is not required (it is not a declaration, therefore it probably won't work). pragma(msg, ...) can already be used for that purpose. template IsNumberWithError(T, string file, int line) { enum bool IsNumberWithError = is( ... static if (!IsNumberWithError) pragma(msg,file, "(", line, "): '", T, "' is not a number."); }An alternative is to give an else to the template constraints, but the error message is at the bottom of the function, making it not easy to find, so I don't like this syntax: int spam(T)(T x) if (IsFoo!T || IsBar!T) { // ... } else { __ctfeWriteln("'", typeid(T), "' is not Foo or Bar."); }I like it. The else clause could perform arbitrary checks to make the error message as helpful as possible.
Feb 10 2012
On 02/10/12 14:04, Timon Gehr wrote:On 02/10/2012 02:47 AM, bearophile wrote:I can see it work for the single template case (i've used ctfe'd functions just for the error messages like that), but what if there are several spam()s with different constraints? The else clauses only get run when no match is found? arturAn alternative is to give an else to the template constraints, but the error message is at the bottom of the function, making it not easy to find, so I don't like this syntax: int spam(T)(T x) if (IsFoo!T || IsBar!T) { // ... } else { __ctfeWriteln("'", typeid(T), "' is not Foo or Bar."); }I like it. The else clause could perform arbitrary checks to make the error message as helpful as possible.
Feb 10 2012
On 02/10/2012 02:21 PM, Artur Skawina wrote:On 02/10/12 14:04, Timon Gehr wrote:That is how I assumed it would work.On 02/10/2012 02:47 AM, bearophile wrote:I can see it work for the single template case (i've used ctfe'd functions just for the error messages like that), but what if there are several spam()s with different constraints? The else clauses only get run when no match is found? arturAn alternative is to give an else to the template constraints, but the error message is at the bottom of the function, making it not easy to find, so I don't like this syntax: int spam(T)(T x) if (IsFoo!T || IsBar!T) { // ... } else { __ctfeWriteln("'", typeid(T), "' is not Foo or Bar."); }I like it. The else clause could perform arbitrary checks to make the error message as helpful as possible.
Feb 10 2012
Timon Gehr:__ctfeWriteln is not required (it is not a declaration, therefore it probably won't work).Then IsNumberWithError needs to be compile-time function.pragma(msg, ...) can already be used for that purpose.I don't like pragma(msg), it even forces a newline at the end. Bye, bearophile
Feb 10 2012
On 02/11/2012 12:27 AM, bearophile wrote:Timon Gehr:I'm not sure what you are saying here.__ctfeWriteln is not required (it is not a declaration, therefore it probably won't work).Then IsNumberWithError needs to be compile-time function.So does __ctfeWriteln.pragma(msg, ...) can already be used for that purpose.I don't like pragma(msg), it even forces a newline at the end.Bye, bearophile
Feb 10 2012
Timon Gehr:I'm not sure what you are saying here.I meant using something like this, instead of a template: bool IsNumberWithError(T, string file=__FILE__, int line=__LINE__)() { enum bool result = is( ... if (!result) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); return result; }So does __ctfeWriteln.I know, but I hope __ctfeWriteln will become __ctfeWrite or someone will write a __ctfeWrite too. See the pull request for discussions about this. Having no way to avoid the ending newline is awful, it forces me to build large strings with appends and print them all at once instead of using just a series or writes. Not having an ending newline was my first requirement for an acceptable compile-time printing function. Bye, bearophile
Feb 10 2012
On 02/11/2012 01:47 AM, bearophile wrote:Timon Gehr:I consider pragma msg a superior solution for this specific case.I'm not sure what you are saying here.I meant using something like this, instead of a template: bool IsNumberWithError(T, string file=__FILE__, int line=__LINE__)() { enum bool result = is( ... if (!result) __ctfeWriteln(file, "(", line, "): '", typeid(T), "' is not a number."); return result; }I agree and don't think there are any valid counter-arguments.So does __ctfeWriteln.I know, but I hope __ctfeWriteln will become __ctfeWrite or someone will write a __ctfeWrite too. See the pull request for discussions about this. Having no way to avoid the ending newline is awful, it forces me to build large strings with appends and print them all at once instead of using just a series or writes. Not having an ending newline was my first requirement for an acceptable compile-time printing function. Bye, bearophile
Feb 10 2012