October 05, 2008
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?

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


>    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








-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
October 05, 2008
Andrei Alexandrescu wrote:

> Rats. I was thinking positive means >= 0 and strictly positive means > 0. According to Wikipedia, positive really means strictly positive and the longer-to-type NonNegative should be used instead :o|. For such a simple concept, a short and sweet name is pivotal. If there are any ideas for a better choice, please make them known.

Ada supports the ability to create new types from the primitive numeric types by adding range constraints to the primitive. The Ada community finds this useful and would appreciate the sort of feature you are talking about. In Ada there are even two predefined subtypes of Integer

	subtype Positive is Integer range 1 .. Integer'Last;
	subtype Natural is Integer range 0 .. Integer'Last;

So for non-negative integers... what about "natural"?

Peter
October 05, 2008
On Sun, 05 Oct 2008 07:36:58 +0400, Ary Borenszweig <ary@esperanto.org.ar> wrote:
> Another problem, from an IDE perspective: "Positive." will trigger autocomplete of Positive's members, ugh.

Thumbs up! That's you all over :)
October 05, 2008
On Sun, 05 Oct 2008 08:41:50 +0400, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> dsimcha wrote:
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
>>> Jason House wrote:
>>>> Andrei Alexandrescu Wrote:
>>>>> Positive.(real) sqrt(Positive.(real) x);
>>>> Ummm... That's not even the correct signature for square root. It
>>>> should accept non negative numbers.
>>> Rats. I was thinking positive means >= 0 and strictly positive means >
>>> 0. According to Wikipedia, positive really means strictly positive and
>>> the longer-to-type NonNegative should be used instead :o|. For such a
>>> simple concept, a short and sweet name is pivotal. If there are any
>>> ideas for a better choice, please make them known.
>>> Andrei
>>  Maybe create the templates as a back end using whatever name, and then create
>> typedefs/aliases for ufloat, udouble, ureal?  This would definitely be consistent
>> with ints and easy to remember.
>
> I think that's a great idea. So, the question becomes: how do people feel about using ufloat, udouble, and ureal?
>
> Andrei

much, Much, MUCH better! Especially once overflows would trigger exceptions I believe these would become very valuable.
October 05, 2008
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.
> 

FWIW: I write large volumes of template code and I like the ! just fine.

> 
> Andrei
> 
October 05, 2008
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 :)
October 05, 2008
downs pisze:
> 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.
>>
> 
> FWIW: I write large volumes of template code and I like the ! just fine.
> 

Same here!

Piotr Modzelewski
keyer@team0xf.com
October 05, 2008
On Sun, 05 Oct 2008 00:12:06 -0500, Andrei Alexandrescu wrote:

> Word followed by exclamation mark. Our brains are wired to interpret that as an exclamation. If it's frequent enough in code, it becomes really jarring.

I too find the form ...

   Template!(arg1, arg2, arg3)

a bit uncomfortable.

If we need to visually distinguish templates (compile-time constructs) from run-time constructs, I would advocate a totally different style all together. Maybe something more along the lines of the DDoc style ...

  @(Template arg1 arg2 arg3)

Nested it would look like ...

  @(This @(That @(TheOther crap)))

But I'm being too left-field, I suspect.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
October 05, 2008
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.
October 05, 2008
Derek Parnell wrote:
> On Sun, 05 Oct 2008 00:12:06 -0500, Andrei Alexandrescu wrote:
> 
>> Word followed by exclamation mark. Our brains are wired to interpret that as an exclamation. If it's frequent enough in code, it becomes really jarring.
> 
> I too find the form ...
> 
>    Template!(arg1, arg2, arg3)
> 
> a bit uncomfortable.
> 
> If we need to visually distinguish templates (compile-time constructs) from
> run-time constructs, I would advocate a totally different style all
> together. Maybe something more along the lines of the DDoc style ...
> 
>   @(Template arg1 arg2 arg3)
> 
> Nested it would look like ...
> 
>   @(This @(That @(TheOther crap)))
> 
> But I'm being too left-field, I suspect.
> 

It's actually a lot quicker to type @( than !( -- it's reasonable for me to use the same shift key for the @ and the (. So I wouldn't much complain about this, except for the ugliness. And !( is also ugly.