Open mimoo opened 2 weeks ago
fn stuff(mut arg: Field)
makes sense to mutate an external variable inside the function.
atm, all the variables passing between the functions are done via copying their values. The reference variable is only usable at local scope.
arg, so now I'm wondering what this does exactly if stuff
attempts to mutate a
, does it fail to compile because stuff
doesn't see a
as mutable?
let mut a = 5;
stuff(a);
if this is the case then functions are pure, which might not be the worst thing for now...
The function stuff(a)
can be called with that mutable variable. Inside that function, that variable a
is seen as immutable. As long as it doesn't directly mutate the argument a
which is not mutable as the syntax mut
is not supported for the function argument, it won't throw error.
we're not super clear on what can be mutated and what cannot be.
For example, can this function call mutate
thing
?imo we should make mutability when we're passing mutable values around. In rust we would have to write
stuff(&mut thing)
. In noname everything is passed by value so I'm not sure what would be a good syntax (there is no such thing asstuff(&thing)
for example. Maybestuff(mut thing)
?How about this example:
can the body of
stuff
mutatearg
? I think it could only if we havefn stuff(mut arg: Field)
, which I don't think is something we currently have in functions/methods.The best thing to do would be to create tests to showcase these examples