July 08, 2009
Nick Sabalausky:
> why in the world is anyone defending the continued existance of "5." and ".5"?<

I'm for disallowing them; 5.0 ad 0.5 are better.
Anyone else pro/against this idea?

Regarding number literals, I'm also for:
B) turning the current octal syntax into a syntax error and introducing a safer octal syntax (see Python 3);
C) adding unbounded integral literals for multi-precisions integral numbers (to be used by bigintegers implemented in the std lib or other D code). (This is to teach D another bit of fishing, using Andrei metaphor).

Bye,
bearophile
July 08, 2009
Nick Sabalausky wrote:
> "Walter Bright" <newshound1@digitalmars.com> wrote in message news:h30845$2kla$2@digitalmars.com...
>> bearophile wrote:
>>> Walter Bright Wrote:
>>>> I like:
>>>>     a .. b+1
>>>> to mean inclusive range.
>>> Me too, but does it work when the upper interval is int.max, char.max, ulong.max, ucent.max, etc?
>> Nope. Wrap around is always a special case, not just for ranges. It's in the nature of 2's complement arithmetic.
> 
> Suppose, hypothetically, that we did have a "right-inclusive-range" token. At the moment I don't give a rat's ass what it actually is, '...', '..#', 'poopiesOnAFlyingStick', whatever. Now, as has been pointed out far to many times by now to still not get:
> 
> a .. int.max+1   // wraparound breaks it
> a right_inclusive_range_tok int.max    // works fine, wraparound isn't even relevant.

Writing an inclusive e.g. loop that goes all the way to the largest integers is tricky no matter what. So this is not a problem with open ranges. Open ranges are there for a good reason.

> And another problem people have already pointed out numerous times with making "a .. b+1" the inclusive range syntax:
> 
> double a=1, b=5;
> // Let's make an inclusive range from 1.0 to 5.0!
> a .. b+1
> // Oh look! 5.5f is in the range! It didn't f*^* work!

b+1 is correct if the range is iterated by 1, as in foreach or as an array index. That's what Walter meant because that's what's in the language. If you want to define a floating-point range that is closed to the right, you may want to use an open range from a to nextUp(b). The nextUp function (defined in std.math by Don I think) returns the very next floating point value. That's exactly what I do in std.random.

> And yet another:
> float a=1, b=somethingReallyLarge;
> assert(b+1 == b);
> // Let's make an inclusive range!
> a .. b+1
> // Oh look! b is missing from the range! It didn't f*^* work again!

This is not a problem with ranges. It's an issue inherent to floating-point arithmetic.

> "a .. b+1" as *the* inclusive range is just plain broken. There is no "Yea, but...!" that can change that.

Yeah, but nextUp.

> And while I'm ranting, why in the world is anyone defending the continued existance of "5." and ".5"? "Because it's already there and it basically still works and isn't hurting anyone." Well it seems to be hurting the adoption of an inclusive range that actually works. I thougt the point of D was to clean up useless cruft like that, even if it still works (header files) to make way for better approaches.

There is no need for a right-closed range in the language. It can be defined with ease as a library, although I'm not finding myself in need of one.


Andrei
July 08, 2009
bearophile wrote:
> C) adding unbounded integral literals for multi-precisions integral
> numbers (to be used by bigintegers implemented in the std lib or
> other D code). (This is to teach D another bit of fishing, using
> Andrei metaphor).

No, it's exactly the opposite - putting on the table a rotten fish. Big integer literals can be accommodated as compile-time strings.


Andrei

July 08, 2009
On Tue, 07 Jul 2009 19:29:21 -0500, Andrei Alexandrescu wrote:

> There is no need for a right-closed range in the language. It can be defined with ease as a library, although I'm not finding myself in need of one.

Process all the characters from 'a' to 'z' inclusive.

Currently, ('a' .. 'z'+1)

Logically, ('a' .. 'z')


-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
July 08, 2009
On Tue, 07 Jul 2009 20:08:55 -0400, bearophile wrote:

> Nick Sabalausky:
>> why in the world is anyone defending the continued existance of "5." and ".5"?<
> 
> I'm for disallowing them; 5.0 ad 0.5 are better.
> Anyone else pro/against this idea?

I would not complain if trailing dot and leading dot were disallowed.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
July 08, 2009
Derek Parnell wrote:
> On Tue, 07 Jul 2009 19:29:21 -0500, Andrei Alexandrescu wrote:
> 
>> There is no need for a right-closed range in the language. It can be defined with ease as a library, although I'm not finding myself in need of one.
> 
> Process all the characters from 'a' to 'z' inclusive.
> 
> Currently, ('a' .. 'z'+1)
> 
> Logically, ('a' .. 'z')

Do we need a language feature for that?

Andrei
July 08, 2009
On Tue, 07 Jul 2009 19:42:00 -0500, Andrei Alexandrescu wrote:

> Derek Parnell wrote:
>> On Tue, 07 Jul 2009 19:29:21 -0500, Andrei Alexandrescu wrote:
>> 
>>> There is no need for a right-closed range in the language. It can be defined with ease as a library, although I'm not finding myself in need of one.
>> 
>> Process all the characters from 'a' to 'z' inclusive.
>> 
>> Currently, ('a' .. 'z'+1)
>> 
>> Logically, ('a' .. 'z')
> 
> Do we need a language feature for that?

Would any answer make a difference?

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
July 08, 2009
Derek Parnell wrote:
> On Tue, 07 Jul 2009 19:42:00 -0500, Andrei Alexandrescu wrote:
> 
>> Derek Parnell wrote:
>>> On Tue, 07 Jul 2009 19:29:21 -0500, Andrei Alexandrescu wrote:
>>>
>>>> There is no need for a right-closed range in the language. It can be defined with ease as a library, although I'm not finding myself in need of one.
>>> Process all the characters from 'a' to 'z' inclusive.
>>>
>>> Currently, ('a' .. 'z'+1)
>>>
>>> Logically, ('a' .. 'z')
>> Do we need a language feature for that?
> 
> Would any answer make a difference?

Of course, as long as it has technical merit.

Andrei
July 08, 2009
Derek Parnell wrote:
> On Tue, 07 Jul 2009 20:08:55 -0400, bearophile wrote:
> 
>> Nick Sabalausky:
>>> why in the world is anyone defending the continued existance of "5." and ".5"?<
>> I'm for disallowing them; 5.0 ad 0.5 are better.
>> Anyone else pro/against this idea?
> 
> I would not complain if trailing dot and leading dot were disallowed.

I think the question that should be asked is: would anyone complain if
they were kept? We have bigger rocks to move than that one.

Andrei
July 08, 2009
Derek Parnell wrote:
> On Tue, 07 Jul 2009 19:42:00 -0500, Andrei Alexandrescu wrote:
> 
>> Derek Parnell wrote:
>>> On Tue, 07 Jul 2009 19:29:21 -0500, Andrei Alexandrescu wrote:
>>>
>>>> There is no need for a right-closed range in the language. It can be defined with ease as a library, although I'm not finding myself in need of one.
>>> Process all the characters from 'a' to 'z' inclusive.
>>>
>>> Currently, ('a' .. 'z'+1)
>>>
>>> Logically, ('a' .. 'z')
>> Do we need a language feature for that?
> 
> Would any answer make a difference?

Of course, as long as it has technical merit.

Andrei