With statement extension

deed via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 26 05:53:49 PDT 2016


Would it be possible to extend current with statement's 
expressiveness by two lowerings:

1) Alias expression/symbol and replace in macro fashion:
    with (a : exprA) { /* use a. will be replaced by exprA by 
compiler. */ }
2) Accept a list of arguments: with (a, b : expr , ...) {} gets 
lowered to
    with (a) with (b : expr) ... {}

As a result, the following would be allowed:

with (aSymb, anExpr, aTempInst, a: symbA, b: exprB, c: tempInstC)
{
     // - current rules for aSymb, anExpr, aTempInst.
     // - a, b and c are replaced by symbA, exprB and tempInstC, 
respectively.
}

For example:

foreach (ref el; elements) with (
     M   : el.aMatrix,
     Ex  : el.someProperties.someModulusX,
     Ey  : el.someProperties.someModulusY,
     G   : el.someProperties.anotherModulus,
     vxy : el.someProperties.aRatio,
     vyx : el.someProperties.anotherRatio)
{
     M = [[1/Ex,    -vyx/Ey,   0],
          [-vxy/Ex,    1/Ey,   0],
          [0,             0, 1/G]];
}

struct SomeProperties (T) {
     T someModulusX;
     T someModulusY;
     T anotherModulus;
     T aRatio;
     T anotherRatio;
     ...
}

struct Element (T) {
     T aMatrix;
     SomeProperties!T someProperties;
     ...
}

Element!float[] elements; elements.length = N;


More information about the Digitalmars-d mailing list