Opened 10 years ago

Closed 10 years ago

#2885 closed enhancement (fixed)

Bind partially evaluated function to local component

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

Description

It doesn't seem possible to bind a partially evaluated function to a local component currently, i.e. something like this:

protected
  ??? someFunc;
algorithm
  someFunc := function someOtherFunc(arg = binding);
  res := someFunc(...);

This would be nice to have when the same function is used many times in a section, see e.g. BackendDAEOptimize.removeUnusedFunctions.

Change History (3)

comment:1 by Per Östlund, 10 years ago

I came up with a way to do this:

function FuncID22<T1, T2, T3, T4>
  input FuncType inFunc;
  output FuncType outFunc := inFunc;

  partial function FuncType
    input T1 inArg1;
    input T2 inArg2;
    output T1 outArg1;
    output T2 outArg2;
  end FuncType;
end FuncID22;

function f
  ...
protected
  partial function FuncType
    input SomeType1 inArg1;
    input SomeType2 inArg2;
    output SomeType1 outArg1;
    output SomeType2 outArg2;
  end FuncType;

  FuncType func;
algorithm
  func := FuncID22(function someFunction(someArg = arg));
  res := func(one_arg);
end f;

A slightly more natural way of doing this would still be nice to have though.

comment:2 by Per Östlund, 10 years ago

I made an attempt to refine this further, and tried this:

partial function FuncType22<T1, T2, T3, T4>
  input T1 inArg1;
  input T2 inArg2;
  output T3 outArg1;
  output T4 outArg2;
end FuncType22;

function FuncID22
  input FuncType22 inFunc;
  output FuncType22 outFunc := inFunc;
end FuncID22;

function f
  ...
protected
  FuncType22 func;
algorithm
  func := FuncID22(function someFunction(someArg = arg));
  (res1, res2) := func(one_arg);
end f;

Unfortunately this doesn't work, because the type of func contains polymorphic types while the call to FuncID22 returns a function with real types, which the compiler doesn't allow. If this would work it would actually be a pretty nice solution I think, since you could just stuff all the needed function signatures and identity functions in e.g. Util. Having to define the specific function signature for the function you want to use is a bit annoying currently.

Last edited 10 years ago by Per Östlund (previous) (diff)

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

Milestone: Bootstrapping1.9.1
Resolution: fixed
Status: newclosed

Fixed in r22758 (parser update).

Note: See TracTickets for help on using tickets.