4 ms·
Couldn't you just pass a reference to your value (i.e. `&T`)? If you absolutely _need_ ownership the function you call could return back the owned value or you
by NIckGeek 1y ago
Couldn't you just pass a reference to your value (i.e. `&T`)? If you absolutely _need_ ownership the function you call could return back the owned value or you could use one of the mechanisms for shared ownership like `Rc<T>`. In a GC'd functional language, you're effectively getting the latter (although usually a different form of GC instead of reference counting)
- zelphirkalt 1y agoI think I could. But then I would need to put & in front of every argument in every procedure definition and also deal with working with references inside the procedure, with the syntax that brings along.
- Mond_ 1y agoFair to be annoyed by this, but not very interesting: This is just a minor syntactical pattern that exists for a very good reason. Syntax is generally the least interesting/important part of languages.
- pepa65 1y agoWhen you pass &variable, I don't think it affects the syntax inside the called function, does it?
- asa400 1y agoCorrect. If you then want to subsequently re-reference or dereference that reference (this happens sometimes), you'll need to accordingly `&` or `*` it, but if you're just using it as is, the bare syntactical `name` (whatever it happens to be) already refers to a reference.
- gf000 1y agoAlso, Rust does implicit dereferencing, so it's not that much of an issue in practice.