September 05, 2014
On Thursday, 4 September 2014 at 20:29:09 UTC, Nordlöw wrote:
> On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
>>    if (low < value < high)
>
> An alternative could be
>
>     if (value in low..high)
>
> but then the problem would be to remember that this range is actually
>
>     [low..high[
>
> to be compliant with range indexing semantics.
>
> But it could still be a useful a quite self-explanatory syntax.

a similar syntax exists in the Pascal-like langs: for example:

    if not (nbr in [0..9]) then...

Which as no direct equivalent in D, except maybe the "library" solution, using std.range.iota + algo.canFind:

    if (!canFind(iota(0, 10, 1), nbr)) ...

The problem is in D "[0..9]" has a completely different signification. But this would be a nice syntax.

September 05, 2014
On Friday, 5 September 2014 at 07:26:45 UTC, klpo wrote:
> On Thursday, 4 September 2014 at 20:29:09 UTC, Nordlöw wrote:
>> On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:

> The problem is in D "[0..9]" has a completely different signification.

All the sins of the past...
September 05, 2014
On Thursday, 4 September 2014 at 22:37:11 UTC, Ary Borenszweig wrote:
>> Correction: foo cannot be pure in this case. But I believe your example
>> is misguiding in this case. The most common use case for this is when
>> foo is pure.
>
> No, why?

foo cannot be pure because it does io.
September 05, 2014
On Friday, 5 September 2014 at 07:49:54 UTC, eles wrote:
> On Friday, 5 September 2014 at 07:26:45 UTC, klpo wrote:
>> On Thursday, 4 September 2014 at 20:29:09 UTC, Nordlöw wrote:
>>> On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
>
>> The problem is in D "[0..9]" has a completely different signification.
>
> All the sins of the past...

In the same fashion, it would be very hard to implement some "D ranges/slices" in Pascal because of this...And I even not speek about Template Meta Programming...

September 05, 2014
On Friday, 5 September 2014 at 07:49:54 UTC, eles wrote:
>> The problem is in D "[0..9]" has a completely different signification.
>
> All the sins of the past...

Is this a sin? The semantics of array slice index ranges are IMHO the right way to do it.
September 07, 2014
On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
> Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as
>
>     if (low < value < high)
>
> ?
>
> This syntax is currently disallowed by DMD.
>
> I'm aware of the risk of a programmer misinterpreting this as
>
>     if ((low < value) < high)
>
> Is this the reason why no languages (including D allows it).
>
> I'm asking for in some cases, where value is a long expression, it would be a nice syntatic sugar to use.

I know Coffeescript has them, they are called 'chained comparison operators' I believe and are a nice syntax cake imo. they are written as expected:
if 10 < a < 20
September 08, 2014
On Thursday, 4 September 2014 at 20:33:45 UTC, Nordlöw wrote:
> On Thursday, 4 September 2014 at 20:25:52 UTC, monarch_dodra wrote:
>> In the case of D, it's a C compatibility thing. Other languages I don't know.
>
> FYI,
>
>     auto x = 1 < 2 < 3;
>
> as C++ is accepted (but warned about) by GCC as
>
> x.cpp:19:20: warning: comparisons like ‘X<=Y<=Z’ do not have their mathematical meaning [-Wparentheses]
>      auto x = 1 < 2 < 3;
>
> Clang gives no warning.

Very surprising clang doesn't. But it willn't take so long to do so.

September 09, 2014
On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
> Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as
>
>     if (low < value < high)
>
> ?
>
> This syntax is currently disallowed by DMD.
>
> I'm aware of the risk of a programmer misinterpreting this as
>
>     if ((low < value) < high)

It is not just that... Imagine this (nothing prevents you from doing it):

   if (foo < bar < baz < trt < mrt < frt /* etc */) {}
September 09, 2014
On Tuesday, 9 September 2014 at 08:50:51 UTC, Dejan Lekic wrote:
> It is not just that... Imagine this (nothing prevents you from doing it):
>
>    if (foo < bar < baz < trt < mrt < frt /* etc */) {}

Is this bad compared to something like

areStrictlyOrdered(foo, bar, baz, trt, mtr, frt)

?
1 2
Next ›   Last »