Void user defined functions that can pass objects by reference

discourse

#1

Is it, or will it be possible to have user defined functions that return a void where users can pass objects by reference? an example piece of code is below.

functions {
  void do_something(vector& vector_to_change, real parameter) {
    vector_to_change *= parameter;
  }
} 

I feel that could make some models more modular, but I may just be spit balling here.


#2

It is not currently possible because arguments are passed by const reference. I wouldn’t hold your breath for it to happen in the near future. Some of the Stan3 design has similar ideas about modularity, but I haven’t seen anything proposed like that for user-defined functions.


#3

Also, before Stan3, there will be tuples in the Stan language, so a user-defined function can just return a bunch of stuff in a tuple.


#4

Allgood, thanks for getting back so quick.