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
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
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.
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
Thanks for the reply
@TeamPuzel @ct @narup https://docs.modular.com/mojo/stdlib/builtin/builtin_list.html
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.