I don’t think Nim does COW automatically. Types like seq and string do it, but 
that’s part of the implementation of the type: internally they contain a 
reference to a shared heap-based array.

You may be thinking of the way that values passed as function parameters aren’t 
copied; this is safe because a function can’t mutate its parameters.

But this doesn’t work for return values. If get_prices returned a pointer to a 
StockPrices object, then the caller might mutate it and affect the object 
stored in the cache.

You can declare the return value of get_prices as `lent`; under the hood this 
will cause it to return a pointer. But that makes the returned value immutable, 
and in any case when you assign it to another object, that’s always a copy.

Reply via email to