Lifetimes and References in Mojo🔥

  Рет қаралды 1,992

Modular

Modular

Күн бұрын

Пікірлер: 10
@liquidmobius
@liquidmobius 4 ай бұрын
Please more videos like this!
@mattcalkins
@mattcalkins 7 ай бұрын
Thank you for making a short video 🎉
@ayoubelmhamdi7920
@ayoubelmhamdi7920 7 ай бұрын
The var keyword is intuitive, we use height language because it is more readable.
@schinken6330
@schinken6330 7 ай бұрын
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?
@XCanG
@XCanG 7 ай бұрын
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?
@agustinpizarro
@agustinpizarro 7 ай бұрын
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.
@XCanG
@XCanG 7 ай бұрын
@@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.
@grzegorzryznar5101
@grzegorzryznar5101 7 ай бұрын
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
@soracc_
@soracc_ 7 ай бұрын
@@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.
@736939
@736939 4 ай бұрын
Who scared that there will be "Rust-lifetimes" kind of shit? )))
MAX Graph API Tutorial
12:17
Modular
Рет қаралды 1,1 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 78 М.
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,3 МЛН
Incredible: Teacher builds airplane to teach kids behavior! #shorts
00:32
Fabiosa Stories
Рет қаралды 9 МЛН
Mojo🔥: a deep dive on ownership with Chris Lattner
48:50
How to Learn Rust
10:36
No Boilerplate
Рет қаралды 565 М.
How much faster has Mojo's dictionary gotten?
7:40
EKB PhD
Рет қаралды 4,2 М.
how can memory safe code STOP HACKERS?
7:43
Low Level
Рет қаралды 117 М.
MAX + Mojo Community Meetings #7
55:39
Modular
Рет қаралды 1,5 М.
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
thoughtbot
Рет қаралды 897 М.
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,3 МЛН