| Thread overview | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 18, 2009 foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats | ||||
|---|---|---|---|---|
| ||||
Consider:
foreach (x; 1.0 .. 4.1) writeln(x);
foreach_reverse (x; 1.0 .. 4.1) writeln(x);
This sucks. foreach with interval for floating-point types should be disallowed.
Andrei
| ||||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | == Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article > Consider: > foreach (x; 1.0 .. 4.1) writeln(x); > foreach_reverse (x; 1.0 .. 4.1) writeln(x); > This sucks. foreach with interval for floating-point types should be > disallowed. > Andrei This one I agree with. I wasn't even aware that the syntax above worked. The use of 4.1 to deal with the fact that the interval is exclusive is a really silly kludge caused by this feature not being intended to be used with floating point intervals. It would be an argument for making the foreach interval loop more powerful instead, except that if you're going to do that, you may as well just use a regular for loop, since foreach interval loops are just a shortcut for this anyhow. | |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu Wrote:
> Consider:
>
> foreach (x; 1.0 .. 4.1) writeln(x);
> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>
> This sucks. foreach with interval for floating-point types should be disallowed.
>
>
> Andrei
I agree that makes little sense.
I'm curious, why the sudden pruning of features? Can you please consider removing SFINAE? I'd also love to see is expressions go the way of the dinosaur. I don't know what their replacement should look like, but there _has_ to be a better and less error prone syntax!
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> Consider:
>
> foreach (x; 1.0 .. 4.1) writeln(x);
> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>
> This sucks. foreach with interval for floating-point types should be disallowed.
As long as you don't also remove the regular for loop with floating-point types.
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jason House | Jason House wrote:
> Andrei Alexandrescu Wrote:
>
>> Consider:
>>
>> foreach (x; 1.0 .. 4.1) writeln(x); foreach_reverse (x; 1.0 .. 4.1)
>> writeln(x);
>>
>> This sucks. foreach with interval for floating-point types should
>> be disallowed.
>>
>>
>> Andrei
>
> I agree that makes little sense.
>
> I'm curious, why the sudden pruning of features? Can you please
> consider removing SFINAE? I'd also love to see is expressions go the
> way of the dinosaur. I don't know what their replacement should look
> like, but there _has_ to be a better and less error prone syntax!
I'm ready to submit the first 121 pages of TDPL to Rough Cuts. Those include an introductory chapter, expressions, and statements. It's hard for me to explain how I feel when I must write about features that I just know are straight wrong. I understand Hal now!
Walter has been very accommodating, huge props to him. He is working on eliminating narrowing conversions for integrals, with a very cool scheme that eliminates most unnecessary narrowing casts.
SFINAE sucks and I hope will be removed too. I don't feel very strongly about is().
Andrei
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | Georg Wrede wrote:
> Andrei Alexandrescu wrote:
>> Consider:
>>
>> foreach (x; 1.0 .. 4.1) writeln(x);
>> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>>
>> This sucks. foreach with interval for floating-point types should be disallowed.
>
>
> As long as you don't also remove the regular for loop with floating-point types.
Yah.
Great, I'm glad to see that others think the same.
Andrei
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jason House | Jason House wrote:
> Andrei Alexandrescu Wrote:
>
>> Consider:
>>
>> foreach (x; 1.0 .. 4.1) writeln(x);
>> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>>
>> This sucks. foreach with interval for floating-point types should be disallowed.
>>
>>
>> Andrei
>
> I agree that makes little sense.
>
> I'm curious, why the sudden pruning of features? Can you please consider removing SFINAE? I'd also love to see is expressions go the way of the dinosaur. I don't know what their replacement should look like, but there _has_ to be a better and less error prone syntax!
I agree about SFINAE, but what's so bad about is()? If it does get removed, I hope whatever replaces it can do all the weird things is can (e.x. is(typeof({}())))
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | Robert Fraser wrote:
> Jason House wrote:
>> Andrei Alexandrescu Wrote:
>>
>>> Consider:
>>>
>>> foreach (x; 1.0 .. 4.1) writeln(x);
>>> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>>>
>>> This sucks. foreach with interval for floating-point types should be disallowed.
>>>
>>>
>>> Andrei
>>
>> I agree that makes little sense.
>>
>> I'm curious, why the sudden pruning of features? Can you please consider removing SFINAE? I'd also love to see is expressions go the way of the dinosaur. I don't know what their replacement should look like, but there _has_ to be a better and less error prone syntax!
>
> I agree about SFINAE, but what's so bad about is()? If it does get removed, I hope whatever replaces it can do all the weird things is can (e.x. is(typeof({}())))
If-clauses in template definitions should do everything SFINAE does, cleaner.
Andrei
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jason House | On Sun, 17 May 2009 21:25:50 -0400, Jason House wrote:
>
> I agree that makes little sense.
>
> I'm curious, why the sudden pruning of features? Can you please consider removing SFINAE? I'd also love to see is expressions go the way of the dinosaur. I don't know what their replacement should look like, but there _has_ to be a better and less error prone syntax!
So, what is SFINAE?
| |||
May 18, 2009 Re: foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | Robert Fraser wrote:
> Jason House wrote:
>> Andrei Alexandrescu Wrote:
>>
>>> Consider:
>>>
>>> foreach (x; 1.0 .. 4.1) writeln(x);
>>> foreach_reverse (x; 1.0 .. 4.1) writeln(x);
>>>
>>> This sucks. foreach with interval for floating-point types should be disallowed.
>>>
>>>
>>> Andrei
>>
>> I agree that makes little sense.
>>
>> I'm curious, why the sudden pruning of features? Can you please consider removing SFINAE? I'd also love to see is expressions go the way of the dinosaur. I don't know what their replacement should look like, but there _has_ to be a better and less error prone syntax!
>
> I agree about SFINAE, but what's so bad about is()? If it does get removed, I hope whatever replaces it can do all the weird things is can (e.x. is(typeof({}())))
Isn't is() also a kind of SFINAE? SFINAE is Substitution Failure Is Not An Error (or so). That means, if there's an error trying to apply a template, the error is silently ignored, and the compiler tries the next template declaration. (Correct me if I'm wrong.) is() does something similar: it tries to compile the expression inside is(), and if it fails, the compiler silently ignores the error and returns "false" to the if.
The problem is: you can't really know if that what you intended to test with is() was false, or if another random semantic error happened inside the is() expression.
Look at this for example:
> writefln("%s", is(typeof(rtzx) == char));
This compiles even if rtzx doesn't exist. But you probably wanted to check the type of rtzx, not it if rtzx exists. If you mistyped rtzx, the compiler will never tell you.
Now Andrei didn't really explain his problem with is()...
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply