October 05, 2008
KennyTM~ wrote:
> Bruce Adams wrote:
>> On Sun, 05 Oct 2008 11:18:24 +0100, KennyTM~ <kennytm@gmail.com> wrote:
>>>
>>> Probably they'd used (0, +∞) and [0, +∞) instead.
>>>
>>> ---
>>>
>>> BTW, negative real numbers can also be indicated as ℝ⁻ (R^- if Unicode is not supported). Is it now special enough to deserve a Negative!() template? :p
>>
>> Nice use of unicode.
>>
>>>
>>> I think these sign checking should be done through contracts or "conditional template" (? whatever it's called; I haven't used one of these yet) instead. Unless you can runtime check that
>>>
>>>    Positive!(double) x = 6;
>>>    Positive!(double) y = 12;
>>
>> Compile time check
>>
>>>    Positive!(double) z = void;
>>
>> This must be an syntax error surely?
> 
> type x = void; means don't initialize x. Or have I missed something?
> 
>>
>>>    z = x - y;  // raises error.
>>
>> The return type of subtraction goes outside the postive domain:
>> i.e. if it needed to exist (which it probably doesn't) the function spec would be:
>>
>> double opMinus(Positive!(double) y, Positive!(double) y);
>>
>>
>> So this is actually:
>>
>> z = cast(Positive!(double))(x - y)
>>
>> Hence there is the necessary check which could be either run-time or compile time.
>>
> 
> Most of the time it can't be compile time because if I've initialized x and y to be some runtime-dependent function (e.g. sin(current time)) then you can't be sure of the sign of x-y. So the check must be made into runtime unless the expression can be CTFE-ed.
> 
>>
>>>    Positive!(double) w;
>>>    din.readf("%g", &w);  // raises error if user enters negative number.
>>>
>>> But I don't think uint, etc now even do these checks.
>>
>> This would ideally work as above but I see your problem.
>> The contract of readf is not tight enough. You should rewrite as:
>>
>> double wtemp;
>> din.read("%g", &wtemp);
>> Positive!(double) w = wtemp;    // type check applied here
>>
> 
> But this is getting ugly :)

Of course. It's because it uses the "!". :o)

Andrei
October 05, 2008
Christopher Wright wrote:
> Andrei Alexandrescu wrote:
>> Christopher Wright wrote:
>>> Andrei Alexandrescu wrote:
>>>> The problem I see with "!" as a template instantiation is not technical. I write a fair amount of templated code and over years the "!" did not grow on me at all. I was time and again consoled by Walter than one day that will happen, but it never did. I also realized that Walter didn't see a problem with it because he writes only little template code.
>>>>
>>>> I didn't have much beef with other oddities unique to D. For example, I found no problem accommodating binary "~" and I was wondering what makes "!" different. I was just looking at a page full of templates and it looked like crap.
>>>>
>>>> One morning I woke up with the sudden realization of what the problem was: the shouting.
>>>
>>> Not only that, but typing it is annoying. First you need to put the right pinky on the shift key, which is a long reach; then you need to put the left pinky on the 1 key, which is a long reach. Then you need to move your left pinky all the way back to the left shift key, which is a short reach, and move your right ring finger up to the 9 key.
>>>
>>> It's a lot of reaching and back and forth.
>>>
>>> But I don't favor '.' since it's already used.
>>
>> I don't favor "." any more than the next guy, but I am glad there is awareness of how unfit a choice "!" is. If you have any ideas, please post them! Ah! I! Exclaimed! Again!
>>
>> Andrei!
> 
> I agree with Mr. Martin II: colon might be an unambiguous option, and for qwerty keyboards, you don't have to switch shift keys. (I use dvorak, so it'd be slightly more awkward, but still a fair bit more easier than a bang.)
> 
> Also, colon's taller than dot, so it's easier to see.

I love the colon. It would be my first preference in fact. Walter wants
to do parsing without symbol tables, and I think that's a worthy goal.
How to parse this?

a = b?c?d:(e):f:(g);

Hmmmm...


Andrei

October 05, 2008
On Sun, Oct 5, 2008 at 12:06 AM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> The problem I see with "!" as a template instantiation is not technical. I write a fair amount of templated code and over years the "!" did not grow on me at all. I was time and again consoled by Walter than one day that will happen, but it never did. I also realized that Walter didn't see a problem with it because he writes only little template code.
>
> I didn't have much beef with other oddities unique to D. For example, I found no problem accommodating binary "~" and I was wondering what makes "!" different. I was just looking at a page full of templates and it looked like crap.
>
> One morning I woke up with the sudden realization of what the problem was: the shouting.
>
> In C, "!" is used as a unary operator. That may seem odd at first, but it nevers follows a word so it's tenuous to associate it with the natural language "!". In D, binary "!" _always_ follows a word, a name, something coming from natural language. So the conotation with exclamation jumps at you.
>
> That's why I find the choice of "!" poor. I believe it can impede to some
> extent acquisition of templates by newcomers, and conversely I believe that
> using .() can make templates more palatable. I tried using ".()" in my code
> and in only a couple of days it looked and felt way better to me. Based on
> that experience, I suggest that "!()" is dropped in favor of ".()" for
> template instantiation for D2.
>
> Sean's argument that "The exclamation mark signifies an assertion of sorts" is exactly where I'd want templates not to be: they should be blended in, not a hiccup from normal code. Serious effort has been, and still is, made in D to avoid shell-shocking people about use of templates, and I think ".()" would be a good step in that direction.

Long argument short:  I don't mind !() at all, and changing it to .()
seems like a pointless pedanticism.  But since you're the one
suggesting it, there's a very good chance of it getting into the
language (if it hasn't already), so there's not much use arguing
against it.
October 05, 2008
Andrei Alexandrescu wrote:
> KennyTM~ wrote:
>> Bruce Adams wrote:
>>> On Sun, 05 Oct 2008 11:18:24 +0100, KennyTM~ <kennytm@gmail.com> wrote:
>>>>
>>>> Probably they'd used (0, +∞) and [0, +∞) instead.
>>>>
>>>> ---
>>>>
>>>> BTW, negative real numbers can also be indicated as ℝ⁻ (R^- if Unicode is not supported). Is it now special enough to deserve a Negative!() template? :p
>>>
>>> Nice use of unicode.
>>>
>>>>
>>>> I think these sign checking should be done through contracts or "conditional template" (? whatever it's called; I haven't used one of these yet) instead. Unless you can runtime check that
>>>>
>>>>    Positive!(double) x = 6;
>>>>    Positive!(double) y = 12;
>>>
>>> Compile time check
>>>
>>>>    Positive!(double) z = void;
>>>
>>> This must be an syntax error surely?
>>
>> type x = void; means don't initialize x. Or have I missed something?
>>
>>>
>>>>    z = x - y;  // raises error.
>>>
>>> The return type of subtraction goes outside the postive domain:
>>> i.e. if it needed to exist (which it probably doesn't) the function spec would be:
>>>
>>> double opMinus(Positive!(double) y, Positive!(double) y);
>>>
>>>
>>> So this is actually:
>>>
>>> z = cast(Positive!(double))(x - y)
>>>
>>> Hence there is the necessary check which could be either run-time or compile time.
>>>
>>
>> Most of the time it can't be compile time because if I've initialized x and y to be some runtime-dependent function (e.g. sin(current time)) then you can't be sure of the sign of x-y. So the check must be made into runtime unless the expression can be CTFE-ed.
>>
>>>
>>>>    Positive!(double) w;
>>>>    din.readf("%g", &w);  // raises error if user enters negative number.
>>>>
>>>> But I don't think uint, etc now even do these checks.
>>>
>>> This would ideally work as above but I see your problem.
>>> The contract of readf is not tight enough. You should rewrite as:
>>>
>>> double wtemp;
>>> din.read("%g", &wtemp);
>>> Positive!(double) w = wtemp;    // type check applied here
>>>
>>
>> But this is getting ugly :)
> 
> Of course. It's because it uses the "!". :o)
> 
> Andrei

I mean using temporary variable explicitly is ugly -_-
October 05, 2008
Denis Koroskin wrote:
> On Sun, 05 Oct 2008 17:31:14 +0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> 
>> Steven Schveighoffer wrote:
>>> If this change is implemented, Walter is going to have a hard time arguing that it's not worth changing invariant to immutable...
>>
>> Speaking of which... guess what he just did :o).
>>
>> Andrei
> 
> 
> Oh, come on... did he? :D

His initiative. Can I use this as a bargaining chip? :o)

Andrei
October 05, 2008
KennyTM~ wrote:
> Christopher Wright wrote:
>> Andrei Alexandrescu wrote:
>>> Christopher Wright wrote:
>>>> Andrei Alexandrescu wrote:
>>>>> The problem I see with "!" as a template instantiation is not technical. I write a fair amount of templated code and over years the "!" did not grow on me at all. I was time and again consoled by Walter than one day that will happen, but it never did. I also realized that Walter didn't see a problem with it because he writes only little template code.
>>>>>
>>>>> I didn't have much beef with other oddities unique to D. For example, I found no problem accommodating binary "~" and I was wondering what makes "!" different. I was just looking at a page full of templates and it looked like crap.
>>>>>
>>>>> One morning I woke up with the sudden realization of what the problem was: the shouting.
>>>>
>>>> Not only that, but typing it is annoying. First you need to put the right pinky on the shift key, which is a long reach; then you need to put the left pinky on the 1 key, which is a long reach. Then you need to move your left pinky all the way back to the left shift key, which is a short reach, and move your right ring finger up to the 9 key.
>>>>
>>>> It's a lot of reaching and back and forth.
>>>>
>>>> But I don't favor '.' since it's already used.
>>>
>>> I don't favor "." any more than the next guy, but I am glad there is awareness of how unfit a choice "!" is. If you have any ideas, please post them! Ah! I! Exclaimed! Again!
>>>
>>> Andrei!
>>
>> I agree with Mr. Martin II: colon might be an unambiguous option, and for qwerty keyboards, you don't have to switch shift keys. (I use dvorak, so it'd be slightly more awkward, but still a fair bit more easier than a bang.)
>>
>> Also, colon's taller than dot, so it's easier to see.
> 
> How to distinguish a label from a template then? Should I print X or Y in the following code?
> 
> import std.stdio;
> 
> class X {
>     static void print () {
>         writeln("Y");
>     }
> }
> 
> template T (x) {
>     void print () {
>         writeln("X");
>     }
> }
> 
> void main () {
>     T:(X).print();
> }

Heh. So this change should come together with abolishing goto :o).

Andrei
October 05, 2008
On Sun, Oct 05, 2008 at 09:29:37AM -0500, Andrei Alexandrescu wrote:
> Heh. So this change should come together with abolishing goto :o).

Noooooooooooooooooooooooooo!

> 
> Andrei

-- 
Adam D. Ruppe
http://arsdnet.net
October 05, 2008
Michel Fortin wrote:
> On 2008-10-05 01:14:17 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> said:
> 
>> I don't favor "." any more than the next guy, but I am glad there is awareness of how unfit a choice "!" is. If you have any ideas, please post them! Ah! I! Exclaimed! Again!
> 
> Hum, I don't think we have much choice, it'll have to be something in this lot:
> 
>     Positive!(real)(joke);
>     Positive.(real)(joke);
>     Positive#(real)(joke);
>     Positive@(real)(joke);
>     Positive&(real)(joke);
>     Positive`(real)(joke);
>     Positive´(real)(joke);
>     Positive^(real)(joke);
>     Positive¨(real)(joke);
>     Positive\(real)(joke);

Positive$(real)(joke);

Does D have a use for # at the moment? I'm surprised it wasn't used for array length instead of $.

L.
October 05, 2008
Andrei Alexandrescu wrote:
> Michel Fortin wrote:
>> On 2008-10-05 01:14:17 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> said:
>>
>> -- snip --
>>
>> Or we could use special delimiter characters:
>>
>>     Positive<real>(joke);
>>     Positive“real”(joke);
>>     Positive«real»(joke);
>>     Positive#real@(joke);
>>
>> Each having its own problem though.
>>
>> My preference still goes to "!(".
> 
> There was also Positive{real}(joke), with which I couldn't find an ambiguity.
>

Ohhhh. Why isn't it considered then? (Suppose we already knew Positive is not a keyword and not preceded by the keywords struct, class, etc.)

> 
> -- snip --
>
October 05, 2008
Lionello Lunesu wrote:
> Michel Fortin wrote:
>> On 2008-10-05 01:14:17 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> said:
>>
>>> I don't favor "." any more than the next guy, but I am glad there is awareness of how unfit a choice "!" is. If you have any ideas, please post them! Ah! I! Exclaimed! Again!
>>
>> Hum, I don't think we have much choice, it'll have to be something in this lot:
>>
>>     Positive!(real)(joke);
>>     Positive.(real)(joke);
>>     Positive#(real)(joke);
>>     Positive@(real)(joke);
>>     Positive&(real)(joke);
>>     Positive`(real)(joke);
>>     Positive´(real)(joke);
>>     Positive^(real)(joke);
>>     Positive¨(real)(joke);
>>     Positive\(real)(joke);
> 
> Positive$(real)(joke);
> 
> Does D have a use for # at the moment? I'm surprised it wasn't used for array length instead of $.
> 
> L.

Yes. #line.

I think $ makes sense because in RegExp $ matches the end of string (or end of line).