Hm, I really hope that Mojo wont add much complications to the language. The only thing what is not obvious here is using square brackets, in python for concatenation string you just use "var += another_var" but you use "aref[] += b", so I don't get why it is needed here. Are references is more like an list of pointers, so first aref equal [a], after first concatenation it become [a, b], then [a, b, b] and because of that you add brackets to sort of joining a list?
aref is basically a pointer, with[] you are dereferencing the pointer, i.e. you get 'a' place in memory. With += you are contatenating 'a' with 'b' storing the result in 'a'. Of course to do the concatenation, mojo will need to allocate a new place (memory) for the new string, but aref will still work as expected.
@@agustinpizarro So, if I getting it right aref is not type of string, but an address in memory and with [] it become a string without allocating new variable in memory? The thing is, in C++ if I remember correctly it was an & to create a reference and * to use, so what "aref[]" here would be C++ equivalent of "*aref". If I getting it right then I think that [] isn't that good of a choice for that. [] used in many places for different things, such as types and type hinting (python and mojo), generics (python), parametrization (mojo), in other languages like of typescript it indicate an array type (ex. "number[]"), so to see this used for reference it a bit counter-intuitive. At least for me. While I considering C++ is very complex on syntax, just for this case it actually simpler.
Need of explicit dereferencing is temporary. In the same video (livestream from 0.7 release), it was said, that with time dereferencing will happen automatically and aref +=b should work fine
@@XCanG All the "different" things you mentioned are actually the same (how is generics a separate thing from typing). Parametrisation in Mojo is *just* a generalisation of Python generics, which already presents in function and types (classes). The two actual different use of [] in Python (and in turn, in Mojo) are typing and subscripting (set/getelem). Deref is not dissimilar to access the only element (so we leave the [] empty) of a cell, so I would argue r[] is very uniform and consistent. Relatedly, there is a Ref type in JAX, and people write r[:] = val or r[None] = val.
Thank you for making a short video 🎉
The var keyword is intuitive, we use height language because it is more readable.
Please more videos like this!
I still dont see the benefit of using a reference over a directly in the first example. `a += b` shouldn't create a copy of a, right?
Who scared that there will be "Rust-lifetimes" kind of shit? )))
Hm, I really hope that Mojo wont add much complications to the language. The only thing what is not obvious here is using square brackets, in python for concatenation string you just use "var += another_var" but you use "aref[] += b", so I don't get why it is needed here. Are references is more like an list of pointers, so first aref equal [a], after first concatenation it become [a, b], then [a, b, b] and because of that you add brackets to sort of joining a list?
aref is basically a pointer, with[] you are dereferencing the pointer, i.e. you get 'a' place in memory. With += you are contatenating 'a' with 'b' storing the result in 'a'. Of course to do the concatenation, mojo will need to allocate a new place (memory) for the new string, but aref will still work as expected.
@@agustinpizarro So, if I getting it right aref is not type of string, but an address in memory and with [] it become a string without allocating new variable in memory? The thing is, in C++ if I remember correctly it was an & to create a reference and * to use, so what "aref[]" here would be C++ equivalent of "*aref".
If I getting it right then I think that [] isn't that good of a choice for that. [] used in many places for different things, such as types and type hinting (python and mojo), generics (python), parametrization (mojo), in other languages like of typescript it indicate an array type (ex. "number[]"), so to see this used for reference it a bit counter-intuitive. At least for me. While I considering C++ is very complex on syntax, just for this case it actually simpler.
Need of explicit dereferencing is temporary. In the same video (livestream from 0.7 release), it was said, that with time dereferencing will happen automatically and aref +=b should work fine
@@XCanG All the "different" things you mentioned are actually the same (how is generics a separate thing from typing). Parametrisation in Mojo is *just* a generalisation of Python generics, which already presents in function and types (classes). The two actual different use of [] in Python (and in turn, in Mojo) are typing and subscripting (set/getelem). Deref is not dissimilar to access the only element (so we leave the [] empty) of a cell, so I would argue r[] is very uniform and consistent. Relatedly, there is a Ref type in JAX, and people write r[:] = val or r[None] = val.