Jump to page: 1 2
Thread overview
Re: GoingNative 2012 to be livestreamed tomorrow - part 2
Feb 10, 2012
bearophile
Feb 10, 2012
Andrej Mitrovic
Feb 10, 2012
Jacob Carlborg
Feb 10, 2012
Timon Gehr
Feb 10, 2012
Jacob Carlborg
Feb 10, 2012
Timon Gehr
Feb 10, 2012
Timon Gehr
Feb 10, 2012
Artur Skawina
Feb 10, 2012
Timon Gehr
Feb 10, 2012
bearophile
Feb 10, 2012
Timon Gehr
Feb 11, 2012
bearophile
Feb 11, 2012
Timon Gehr
February 10, 2012
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
February 10, 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.
February 10, 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
February 10, 2012
On 02/10/2012 08:17 AM, Jacob Carlborg wrote:
> 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.
>

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.
February 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.


February 10, 2012
On 2012-02-10 13:58, Timon Gehr wrote:
> On 02/10/2012 08:17 AM, Jacob Carlborg wrote:
>> 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.
>>
>
> 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.

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 Carlborg
February 10, 2012
On 02/10/12 14:04, Timon Gehr wrote:
> On 02/10/2012 02:47 AM, bearophile wrote:
>> 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.

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?

artur
February 10, 2012
On 02/10/2012 02:44 PM, Jacob Carlborg wrote:
> On 2012-02-10 13:58, Timon Gehr wrote:
>> On 02/10/2012 08:17 AM, Jacob Carlborg wrote:
>>> 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.
>>>
>>
>> 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.
>
> 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".
>

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.








February 10, 2012
On 02/10/2012 02:21 PM, Artur Skawina wrote:
> On 02/10/12 14:04, Timon Gehr wrote:
>> On 02/10/2012 02:47 AM, bearophile wrote:
>>> 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.
>
> 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?
>
> artur

That is how I assumed it would work.
February 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
« First   ‹ Prev
1 2