这是indexloc提供的服务,不要输入任何密码
Skip to content

Passing down additional data to functions that are called transitively #1085

@SimonCockx

Description

@SimonCockx

See parent issue: #1077

Typically, a translation consists of many transitive function calls, e.g.,

MapDocument -> MapTradeInformation -> MapProduct -> MapSecurityLending

Given the extension ExtendedTradeInformation which adds a default currency, suppose we need to access this property when mapping a SecurityLending. Since, when overriding functions, we cannot add additional parameters, we need a different way to communicate this new property from MapTradeInformation down to MapSecurityLending.

To achieve this, we introduce the concept of a context.

scope MyScope

type MyContext:
  defaultCurrency DefaultCurrency (1..1)

func ExtendedMapTradeInformation overrides MapTradeInformation:
  inputs:
    tradeInformation TradeInformation (1..1)
  output:
    result Trade (1..1)
  context:
    context MyContext (1..1)
  
  set context -> defaultCurrency: (tradeInformation as ExtendedTradeInformation) -> defaultCurrency
  
  set result: proceed(tradeInformation)

func ExtendedMapSecurityLending overrides MapSecurityLending:
  inputs:
    securityLending SecurityLending (1..1)
  output:
    result Foo (1..1)
  context:
    context MyContext (1..1)
  
  set result: proceed(tradeInformation)
  set result -> currency: result -> currency default context -> defaultCurrency

In the above example, three important concepts are illustrated.

  1. We declare that a function is using a context with a new section below the output of the function: context: context MyContext (1..1).
  2. In ExtendedMapTradeInformation, we set a property in the context using set context -> defaultCurrency: ..., similar to how we set the output of a function.
  3. In ExtendedMapSecurityLending, we access a property from the context using context -> defaultCurrency, similar to how we access the input of a function.

In order for functions to stay stateless, any changes to a context are discarded right after the end of a function call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsubject: code generationThis issue is about code generationsubject: model validationThis issue is about validation of Rosetta models, such as the type systemsubject: syntaxThis issue is about the syntax of Rosetta

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions