Re: Allowing Expressions such as (low value high)

2014-09-09 Thread Dejan Lekic via Digitalmars-d-learn
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

Re: Allowing Expressions such as (low value high)

2014-09-09 Thread Nordlöw
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) ?

Re: Allowing Expressions such as (low value high)

2014-09-07 Thread nikki via Digitalmars-d-learn
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

Re: Allowing Expressions such as (low value high)

2014-09-07 Thread AsmMan via Digitalmars-d-learn
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

Re: Allowing Expressions such as (low value high)

2014-09-05 Thread klpo via Digitalmars-d-learn
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[

Re: Allowing Expressions such as (low value high)

2014-09-05 Thread eles via Digitalmars-d-learn
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...

Re: Allowing Expressions such as (low value high)

2014-09-05 Thread Nordlöw
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.

Re: Allowing Expressions such as (low value high)

2014-09-05 Thread babu via Digitalmars-d-learn
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

Allowing Expressions such as (low value high)

2014-09-04 Thread Nordlöw
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

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
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

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Nordlöw
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

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Nordlöw
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

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Ary Borenszweig via Digitalmars-d-learn
On 9/4/14, 5:03 PM, 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

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 20:45:41 UTC, Ary Borenszweig wrote: That's because the middle expression in the comparison is first assigned to a temporary variable, so `foo` is only invoked once. This makes both the code more readable, efficient and saves the programmer from having to save

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Nordlöw
On Thursday, 4 September 2014 at 22:02:20 UTC, Nordlöw wrote: D can also, in this case, do (or will do) common sub-expression elimination because it has a strict memory model (const and immutability) and function purity (template inference). Correction: foo cannot be pure in this case. But I

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Matt Soucy via Digitalmars-d-learn
On 09/04/2014 04:03 PM, 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

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread Ary Borenszweig via Digitalmars-d-learn
On 9/4/14, 7:03 PM, Nordlöw wrote: On Thursday, 4 September 2014 at 22:02:20 UTC, Nordlöw wrote: D can also, in this case, do (or will do) common sub-expression elimination because it has a strict memory model (const and immutability) and function purity (template inference). Correction: foo

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread ketmar via Digitalmars-d-learn
On Thu, 04 Sep 2014 20:29:08 + Nordlöw via Digitalmars-d-learn digitalmars-d-learn@puremagic.com 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) and then we need new overload for 'in'