M
Modular12mo ago
ct

How can I create a Python list to add and remove structs?

I am trying mojo and would like to define a few structs and use a Python like dynamic list. I would like to be able to add and remove structs, iterate over items etc.
6 Replies
narup
narup12mo ago
DynamicVector works if you can have all the fields in struct as register passable If not you can create an Array using pointer for data. Mojo docs has example
ct
ct12mo ago
I did read "https://docs.modular.com/mojo/programming-manual.html" a while ago and did not find how to use Python like list. There is an example of implementation of array but it is not dynamic.
TeamPuzel
TeamPuzel12mo ago
There won’t be a list in Mojo until it supports traits. Without them you can’t implement a type-safe heterogeneous collection, or even a homogeneous one with iteration, equality comparison etc From what I’ve heard traits will be supported around the end of this year, at least partially
ct
ct12mo ago
Thanks for the reply
TeamPuzel
TeamPuzel12mo ago
This is an immutable list literal for constructing collections, not a list. You can see that the module does not contain an implementation, just the literal.
Want results from more Discord servers?
Add your server