V Forum

[ log in ]

Allow "opt-in" mutable function parameters

wdevore 2019-04-11 12:56
I am not sure I appreciate the idea behind immutable parameters on functions (i.e. partial purity).
Wouldn't this cause a lot of allocations and large return variables. This seems like it would slow V down during run time.

For example, If I had a function like:
```
fn (b mut baker) make_bread(cheese CheeseType, bread BreadType) CheeseType , BreadType {...}
```

Wouldn't an "opt-in" approach using `mut` allow the programmer more flexibility?
```
fn (b mut baker) make_bread(cheese mut CheeseType, bread mut BreadType) xyz {...}
```
medvednikov 2019-04-11 22:01
Yes, several people raised this concern.

The goal is to optimize this behind the scenes. If it turns out some cases are not optimizable, I'll allow it.
wdevore 2019-04-12 21:25
Cool. Thanks for the feedback.
medvednikov 2019-05-10 21:38
This has been implemented:

https://vlang.io/docs#recvs



Powered by Vorum, open-source blogging/forum software written in V