M
Modular•5mo ago
bapbaj

Returning references

Is it possible to return references in Mojo?
7 Replies
sora
sora•5mo ago
Yes. You can simply use Reference
bapbaj
bapbajOP•5mo ago
Thanks, I saw that, but it wasn't clear to me: is Reference compiled to a simple pointer, or is it some reference-counted thing?
sora
sora•5mo ago
It's a pointer (with lifetime tracking). For ref-count, you may use Arc
bapbaj
bapbajOP•5mo ago
https://github.com/modularml/mojo/blob/main/proposals/lifetimes-and-provenance.md I was reading this and it said that it's "impossible to return references." Is this doc outdated then?
GitHub
mojo/proposals/lifetimes-and-provenance.md at main · modularml/mojo
The Mojo Programming Language. Contribute to modularml/mojo development by creating an account on GitHub.
sora
sora•5mo ago
Ah, this proposal has already been implemented for a while now. This is design doc, so I won't say it's outdated per se, but it indeed describes an older state of the language.
bapbaj
bapbajOP•5mo ago
Got it, thanks 🙂
sora
sora•5mo ago
I think we are indeed lacking in documentation regarding Reference etc. So, if you see any thing you want to be explained better, you could raise an issue on GH to help the team prioritize.
Want results from more Discord servers?
Add your server