Missing python-like chaining in D

Ali Çehreli acehreli at yahoo.com
Mon Feb 21 18:05:41 UTC 2022


On 2/21/22 02:27, forkit wrote:

 >>> writeln(1 < 2 < 3 < 4 > 3 == 3); // true

 > cat.meow().eat().sleep().play();

That misunderstanding (or miscommunication) is reason enough why such 
loose semantics should not be in any serious programming language.

So, Python is happy with the fact that the result of 1 < 2 is sometimes 
Boolean but sometimes 2? (Note that in chaining, not the result but one 
of the arguments is used; and the chosen argument happens to be the one 
that's "close" to the next operator. Ha ha! :) How convenient... And why 
would 'a > b < c' not mean "a is greater than b and a is less than c" or 
"a is greater than b OR b is less than c"? I can guess: They picked the 
only semantic that could possibly be explained that could work. And then 
they must have slapped on a rationale: "Checking more than two 
conditions is very common in Programming Languages." I found that 
inaccurate sentence copy-pasted in multiple blog posts:

- They must mean "more than one condition", not "two"

- They mean "program", not "programming language"

- They ommit the supposed domain where that claim may be true (I might 
have found a use for this feature perhaps once, if ever? Not sure...)

I think this is an example of blind leading blind in that community.

Ali



More information about the Digitalmars-d mailing list