Can a function use data?

Can a function use a variable from the data block? My use case is that I am supplying a constant that I don’t want to hardcode to a transformation, but at the same time providing it as an argument is unnecessarily repetitive. MWE:

functions {
  vector divbyA(vector x) {
    return x ./ A;
data {
  real A;

which of course does not compile as A is not in scope. Is there a workaround?

Pass A as an argument to your function.

Not yet. There’s no lexical scoping out of functions in Stan.

I’m thinking about designs for proper closures now that C++11 supports them with general lambdas. Then it’d be easy to write something like this on the fly. We may need to think a lot more about first class function types (also supported by C++11 std::function.