Skip to content

local functions block #2024

@bgoodri

Description

@bgoodri

Summary:

The Stan language should have the ability to create user-defined member functions of the model class

Description:

At the last meeting, we proposed adding a new block to the Stan language that perhaps could be called local functions that would go after transformed data. The Stan syntax would be the same as in the functions block but unlike the user-defined functions in the functions block the user-defined functions in the local functions block could refer to objects in the data and transformed data blocks without explicitly passing them as arguments. This would make such functions much easier to use than integrate_ode, which requires fixed arguments to be passed in a very clunky way. It might look like

data {
  int<lower=1> N;
}
transformed data {
  int<lower=2> two_N;
  two_N = 2 * N;
}
local functions {
  void what_is_2N() {
    print("2N = ", two_N);
  }
}

Reproducible Steps:

Does not currently exist.

Current Output:

Does not currently exist.

Expected Output:

Whatever the user-defined function returns

Additional Information:

None

Current Version:

v2.11.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions