Suggestions on syntax to express mathematical formula concisely

前端 未结 13 1384
予麋鹿
予麋鹿 2021-02-02 08:46

I am developing functional domain specific embedded language within C++ to translate formulas into working code as concisely and accurately as possible.

I posted a proto

13条回答
  •  忘掉有多难
    2021-02-02 09:15

    Encapsulate!

    I'm sure you'll find some syntax that balances concision and clarity. However good it is, it will be vastly improved by providing encapsulation. So instead of

    qty = sum(range(i) < j < N))[(T(i,j) - T(j,i))/e(i+j)];
    

    You could have

    Texpr = (T(i,j) - T(j,i))/e(i+j);
    RangeExpr = (range(i) < j < N);
    qty = sum(RangeExpr)[ Texpr ];
    

    That might afford you more verbosity in the syntax.

    PS: Isn't this Mathematica? Mathematica C/C++ Language Interface

提交回复
热议问题