Allowing Expressions such as (low < value < high)

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 4 15:02:18 PDT 2014


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 that value to a 
> temporary variable itself.
>
> I guess D doesn't have it because it has (...why?) to be 
> compatible with C's semantic. Also, as you can see, it's not 
> that trivial to implement because you need to assign that value 
> first to a temporary variable.

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


More information about the Digitalmars-d-learn mailing list