I think this is a really subtle design question that needs to look at the tradeoff between convenience and safety.
So, generally speaking, you can always @take
an owned variable to unpack it, and ship that off to the external method. This trips the .moved = true
so you can’t use the variable after that point. You would have to create a new owned variable, like
@own y = maybe_mutating_function!(@take x)
I think this design might be ok for many things. It’s quite similar to a lot of Rust code, when a variable’s ownership is lost. It also lets you gradually increase the number of functions with borrow checking, without forcing you to update your whole codebase at once.
Now, I’ve also written some of the methods needed for collections and math:
We can probably add some other basic stuff. The main thing is to know when it’s okay to have :write
versus :read
in accesses as that determines what variable states are allowed when using them.
All other methods not provided here, the user would need to specify explicitly. I thought about having a special BorrowedArray{T} <: AbstractArray{T}
type for arrays, and another for Number
, but I realised it is problematic to do this sort of thing implicitly.
In some sense, we actually want the MethodError, so that the user is forced to either @take
the variable, or explicitly declare functions as being borrow-compatible.