@ArneBab lots of good stuff in there!
"Alternative: Declare the return type of a function inside the function" -- this is what I do for any function which returns anything other than a scalar of one of the simple built-in types.
The part about accumulation is quite subtle -- variables can have a property "save" which makes them persistent across calls.
Any initialisation in the declaration line implicitly makes them "save", which is often counter intuitive.
Reminds me of python's: def a(b=[]):