With statement extension
deed via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 27 06:55:21 PDT 2016
On Tuesday, 26 April 2016 at 12:53:49 UTC, deed wrote:
> For example:
A stronger example would be a scope with two similar types, i.e.:
void foo (Matrix matrix, SameType e1, SameType e2)
{
with (
M : matrix.rawArr;
Ex1 : e1.someProperties.someModulusX,
Ey1 : e1.someProperties.someModulusY,
Ex2 : e2.someProperties.someModulusX,
Ey2 : e2.someProperties.someModulusY,
v : e1.someProperties.aRatio)
foreach (i; ...) foreach (j; ...) {
M[...] = Ex1 > Ex2 ?
1/v^^2 * sqrt(v * (Ex1 + Ex2)^^2 + v^^2 * (Ey1 - Ey2)^^2)
:
1/v^^2 * sqrt(v * (Ex1 + Ex2)^^2 + v^^2 * (Ey1 + Ey2)^^2)
;
}
}
Current with-statement gets you next to nowhere here:
void foo (Matrix matrix, SameType e1, SameType e2)
{
with (matrix)
with (e1.someProperties)
foreach (i; ...) foreach (j; ...) {
rawArr[...] = e1.someProperties.someModulusX >
e2.someProperties.someModulusX ?
1/aRatio^^2 * sqrt( aRatio *
(e1.someProperties.someModulusX
+
e2.someProperties.someModulusX)^^2
+ aRatio^^2 *
(e1.someProperties.someModulusY
-
e2.someProperties.someModulusY)^^2) :
1/aRatio^^2 * sqrt( aRatio *
(e1.someProperties.someModulusX
+
e2.someProperties.someModulusX)^^2
+ aRatio^^2 *
(e1.someProperties.someModulusY)
+
e2.someProperties.someModulusY)^^2) ;
}
}
And let's say it would be much more descriptive to name e1 and e2
as currentSquare and adjacentTriangle and there you go..
Apparently, the two proposed lowerings could boost the
expressiveness of the language without breakage.
More information about the Digitalmars-d
mailing list