﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2811	Add support for list range expressions in for-loops	Per Östlund	Martin Sjölund	"It would be nice if lists could be used as the range expression in for-loops in MetaModelica, to make it possible to write functions like this:
{{{#!mo
function splitOnTrue<T>
  input list<T> inList;
  input PredicateFunc inFunc;
  output list<T> outTrueList = {};
  output list<T> outFalseList = {};

  partial function PredicateFunc
    input T inElement;
    output Boolean outResult;
  end PredicateFunc;
algorithm
  for e in inList loop  // <- Iterate over list.
    if inFunc(e) then
      outTrueList := e :: outTrueList;
    else
      outFalseList := e :: outFalseList;
    end if;
  end for;

  outTrueList := listReverse(outTrueList);
  outFalseList := listReverse(outFalseList);
end splitOnTrue;
}}}
Currently we only allow iteration over arrays, but making the frontend accept lists too is trivial. The generated code is specific for arrays though, so at the very least the code generator needs to be updated to handle lists. Maybe something needs to be done about polymorphic types too, I don't know how that's handled right now.

while-loops can be used as a workaround, but then you need to handle the iteration yourself which isn't quite as nice."	enhancement	closed	normal	Bootstrapping	MetaModelica	trunk	fixed		
