stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
138 stars 44 forks source link

[FR] Tuple unpacking #1349

Closed WardBrian closed 9 months ago

WardBrian commented 10 months ago

As described in the design doc, it would be nice to support tuple unpacking or "destructuring assignment". Example:

int x;
int y;
(x, y) = (1, 2)

This would be great to support for tuple-returning functions like #1346

Some things to keep in mind:

(x,y) = (y,x); // should swap variables gracefully
(a,b) = something_expensive(); // should only call function _once_

This can be implemented entirely in the frontend, since it in general desugars to (using the example above)

temp_tuple = something_expensive()
a = temp_tuple.1
b = temp_tuple.2