Opened 9 years ago

Last modified 7 years ago

#3709 closed enhancement

MetaModelica extension: bidirectional variables — at Initial Version

Reported by: Martin Sjölund Owned by: Martin Sjölund
Priority: high Milestone: 1.11.0
Component: MetaModelica Version: v1.9.4-dev-nightly
Keywords: Cc: Adrian Pop, Per Östlund, openmodelicadevelopers@…

Description

One annoying thing with MetaModelica is the inability to assign to input variables, and the fact that you need different names for the input and output variables when traversing data structures.

I propose a syntactic sugar for handling bidirectional variables:

function f
  bidirectional Exp exp; // or input output Exp exp;
  bidirectional Integer i;
algorithm
  exp := match exp
    case ICONST() then ICONST(exp.value+i);
    else exp;
  end match;
end f;

Which is almost equivalent to:

function f
  input Exp $in_exp;
  input Integer $in_i;
  output Exp exp=$in_exp;
  output Integer i=$in_i;
algorithm
  exp := match exp
    case ICONST() then ICONST(exp.value+i);
    else exp;
  end match;
end f;

(The difference being that the type of the function would keep the original names when using named arguments for calling the function).

The benefit would be shorter code and better names. There would be no need to use prefixes in and out to differentiate between two local variables.

Change History (0)

Note: See TracTickets for help on using tickets.