Feature request: Convert variables from mutable to immutable at runtime #1791
Locked
LiamSwayne
started this conversation in
Ideas
Replies: 1 comment
-
Also, I'm not really sure what you're trying to accomplish here, that can't already be done with Mojo: var x: Int = 1
if not runtime_expr:
x += 1 # No runtime mutability checking needed Without a compelling real world example, I don't see a need for something like this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be helpful to be able to make a variable immutable based on control flow or keywords.
If
fix
was the keyword used to convert mutable data types to an immutable state, it could look like this:This behavior can be produced with
struct
s, but to my knowledge requires running control flow and checking for mutability after every function call to an instance. I assume there is a much more efficient way to implement a feature like this, even in astruct
. Perhaps a boolean tacked on to the instance could hold it's value until it is freed by thefix
call, and subsequent checks for mutability would throw an error when trying to mutate the variable due to being unable to access it's correlating boolean. I am sure there is a better approach, but even a decorator on astruct
to provide this functionality with some overhead would be very useful.Beta Was this translation helpful? Give feedback.
All reactions