Missing python-like chaining in D

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Feb 23 01:20:38 UTC 2022


On Wed, Feb 23, 2022 at 02:03:37AM +0100, Timon Gehr via Digitalmars-d wrote:
> On 22.02.22 11:47, Patrick Schluter wrote:
[...]
> > > ..you can't deny, that there is beauty in this mess.
> > > 
> > > 1 < 2 < 3 < 4 > 3 == 3
> > 
> > Nope.
> 
> Indeed, it's not a particularly helpful motivating example. x)
> 
> I have sometimes wished for this when checking that some more
> complicated expression is within some bounds, where the expression is
> not complicated enough to justify reshaping the code and introducing a
> temporary variable.
> 
> e.g.: low <= a[2*i+1] <= high
> vs:   low <= a[2*i+1] && a[2*i+1] <= high

	import std.algorithm : ordered;
	if (ordered(low, a[2*i+1], high)) ...


T

-- 
What do you call optometrist jokes? Vitreous humor.


More information about the Digitalmars-d mailing list