Yes, this is a common way to do this. Usually to get the non-mutating behavior
you need to make a copy first anyway. (Some languages just do so implicitly and
don't allow anything else.) Sometimes, as Kristoffer mentions, there might be a
way to construct a new object directly instead of
Thanks for these infos. I will definitely pre-allocate memory (in fact
I do in the real code).
t
Le samedi 22 août 2015 à 14:24 -0700, Sisyphuss a écrit :
I don't think it's much less efficient to copy` in your second
example. In
the second function., you should allocate memory for `y`
What do you mean copying the object is inefficient? Do you mean that it is
cheaper to build it from scratch than to start with the copy?
On Saturday, August 22, 2015 at 9:51:48 PM UTC+2, Timothée Poisot wrote:
Hi,
I caught myself wondering about the correct way to use function and
Another (maybe better) option is
```
baz!(z,x) = begin ... return z; end
baz(x) = baz!(similar(x),x)
```
You can call them by
```
baz!(x,x)
z = baz(x)
```
On Saturday, August 22, 2015 at 11:24:51 PM UTC+2, Sisyphuss wrote:
I don't think it's much less efficient to copy` in your second