Opened 10 years ago

Last modified 10 years ago

#2819 new enhancement

List comprehensions that create zero or multiple lists

Reported by: Per Östlund Owned by: Martin Sjölund
Priority: normal Milestone: Future
Component: MetaModelica Version: trunk
Keywords: Cc:

Description (last modified by Per Östlund)

It would be nice if list comprehensions were a bit more flexible regarding the amount of lists created, so that something like this would work (possibly with some other syntax):

function f1
  input Integer x;
algorithm
  print(intString(x) + "\n");
end f1;

function f2
  input Integer x;
  output Integer y := x*2;
  output Integer z := x*3;
end f2;

function test
  output list<Integer> l1;
  output list<Integer> l2;
algorithm
  list(f1(i) for i in 1:3); // 'map' that doesn't return anything
  (l1, l2) := list(f2(i) for i in 1:3); // 'map' that returns two results for each element
end test;

Change History (2)

comment:1 by Per Östlund, 10 years ago

Description: modified (diff)

comment:2 by Martin Sjölund, 10 years ago

This is very problematic to implement due to the fact that none of Types.matchType are able to perform type conversion on a tuple call. And there does not exist any CAST operator for tuples either (and not in code generation).

Note: See TracTickets for help on using tickets.