hello,
I’d like to discuss the readability of Mojo’s ^ transfer sigil.
The [official ownership documentation] explains that when a function takes a var argument, the caller can explicitly transfer ownership by adding ^ at the call site.
For example:
def take_text(var text: String):
text += "!"
print(text)
def main():
var message = "Hello"
take_text(message^)
This is an important semantic distinction: after take_text(message^), message is no longer initialized and cannot be used again.
For example, this does not compile:
def main():
var message = "Hello"
take_text(message^)
print(message) # error: use of uninitialized value 'message'
I understand the rationale behind using a postfix ^, and it is certainly compact. However, I find it somewhat easy to overlook when reading code, especially when the call is embedded in a larger expression or when there are many arguments.
The difference between:
take_text(message)
and:
take_text(message^)
is semantically significant, but visually the distinction is relatively subtle.
Could the syntax make the ownership flow more explicit?
For example, would a directional syntax be easier to recognize?
Instead of:
take_text(message^)
something like:
take_text(<| message)
or:
take_text(message |>)
could visually communicate that ownership is moving from message into the function.
Conceptually:
message ---> take_text
This might make ownership transfer more apparent when scanning code or reviewing a diff.
For example:
def main():
var message = "Hello"
take_text(<| message)
or:
def main():
var message = "Hello"
take_text(message |>)
The main question is not whether <| or |> is necessarily the right syntax. Rather:
Is the current ^ sigil sufficiently visible for something as important as ending the lifetime of a variable?
There are also some interesting trade-offs here.
-
^is compact and already established in Mojo. -
A directional syntax could make the ownership flow more visually obvious.
-
|>already has a strong association with pipelines in other languages, so it might introduce ambiguity. -
<|may have its own readability or parsing considerations. -
Any syntax change would have a significant migration and ecosystem cost.
I’m curious how other Mojo users feel about this. Do you find message^ sufficiently clear in practice, or would a more visually distinctive transfer operator make ownership semantics easier to recognize?
And if you agree that the current syntax could be more visible, what syntax would you propose?