I’m trying to write a function that returns an integrated quantity. And so, it requires that a function for the integrand be defined. However, I’m not succeeding in calling one function from within another.

If I define them separately, with forward declaration:

```
real integrand(real x, real xc, real[] theta);
real beta_diff(real[] theta);
real integrand(real x, real xc, real[] theta) {
return beta_lpdf(x | theta[1], theta[2]) + beta_lcdf(x | theta[3], theta[4]);
}
real beta_diff(real[] theta){
return integrate_1d(integrand, 0, 1, theta)
}
```

I get: variable “integrand” does not exist.

If I try to define the integrand function within the beta_diff function:

```
real beta_diff(real[] theta){
real integrand(real x, real xc, real[] theta) {
return beta_lpdf(x | theta[1], theta[2]) + beta_lcdf(x | theta[3], theta[4]);
}
return integrate_1d(integrand, 0, 1, theta)
}
```

I get a parser error.

Any ideas? Is this possible, or can I work with only non nested functions and have to do all the rest within the model block?

Thanks!