Changes between Version 6 and Version 7 of WritingEfficientMetaModelica


Ignore:
Timestamp:
2014-10-15T12:25:04Z (10 years ago)
Author:
Martin Sjölund
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WritingEfficientMetaModelica

    v6 v7  
    1 = Writing efficient MetaModelica code =
     1= Writing efficient, readable, and maintainable MetaModelica code =
    22
    33In the bootstrapped compiler, together with the extended MetaModelica/Modelica things you can use there are some restrictions:
    44== Use builtin functions and operators whenever possible ==
    55Builtin functions have implementations that are better than you can achieve using MetaModelica code (for example: stringAppendList and stringDelimitList only use a single memory allocation).
     6
     7It is possible to use many constructs from the Modelica language, such as list comprehensions, partial function application, if-expressions, if-statements, for-loops and while-loops.
    68
    79List reductions (like Modelica array reductions) can be used to avoid the extra listReverse at the end of functions written by the user. They are also easier to read. Example:
     
    4951}}}
    5052
     53Instead of being required to create new functions in order to pass higher-order functions in function calls, consider using partial function application (closures) instead:
     54{{{#!mo
     55List.exist(exps, function Expression.expEqual(e2=exp)); // Bootstrapping
     56List.exist1(exps, Expression.expEqual, exp); // RML; requires additional functions to be maintained in List.mo
     57}}}
     58
    5159== Avoid matchcontinue, use tail recursion ==
    5260`matchcontinue` is slow. Whenever possible, use `match` instead. This avoids calling `setjmp`.