Changes between Version 6 and Version 7 of WritingEfficientMetaModelica
- Timestamp:
- 2014-10-15T12:25:04Z (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WritingEfficientMetaModelica
v6 v7 1 = Writing efficient MetaModelica code =1 = Writing efficient, readable, and maintainable MetaModelica code = 2 2 3 3 In the bootstrapped compiler, together with the extended MetaModelica/Modelica things you can use there are some restrictions: 4 4 == Use builtin functions and operators whenever possible == 5 5 Builtin 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 7 It 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. 6 8 7 9 List 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: … … 49 51 }}} 50 52 53 Instead 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 55 List.exist(exps, function Expression.expEqual(e2=exp)); // Bootstrapping 56 List.exist1(exps, Expression.expEqual, exp); // RML; requires additional functions to be maintained in List.mo 57 }}} 58 51 59 == Avoid matchcontinue, use tail recursion == 52 60 `matchcontinue` is slow. Whenever possible, use `match` instead. This avoids calling `setjmp`.