-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
be clearer on mutability #134
Comments
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 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 |
I faced this problem when I was planning to test the example given in #224 . Below, even if the room variable is mut, we are not able to write functions like update_size since it is not possible to pass self as mut. I don't know if this is necessary to have but just found it relevant to share.
|
I think we're in a model where functions/methods have to produce a new object instead of updating the current object. It's more "functional" and doesn't really save you any constraints underneath so maybe we should keep it this way? |
mmm, I think it is a natural mind flow that people would like to modify the struct fields within the methods. Requiring them to return a new struct if modifications happen seems to be quite cumbersome (I may miss something here). |
yeah I'm not against that path either, but the problem is... what keyword do we introduce for a mutable ref? but this might be weird for people coming from Rust, who will see Maybe (this is where my train of thought stopped last time I thought about it, and then I figured the current way sort of works and doesn't add more lines of code) |
IIUC, the current Line 267 in c076b4a
So maybe just |
mmm, I would still vote for but also, when we are passing such a variable as argument to a function, I think we should have a syntax to indicate that the variable is going to be mutated. So in Rust we would have: fn thing(val: &mut Field);
// ...
let mut x = 5;
thing(&mut x); in noname what would be the equivalent of that code? fn thing(val: mutref Field);
// ...
let mut x = 5;
thing(mutref x); that looks ugly :D |
Cool. Let's go with the |
Alright, I am on it. |
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
The text was updated successfully, but these errors were encountered: