What's the proper way to use List?
Anytime I use List, I hit issues with Reference. Looking through docs, I see that Reference is related to unsafe memory operations.
I'm looking into how to avoid variable-length collections using parameters, but I'd like to get this working first, at least. Any ideas?
Edit: I tried adding a
var count: Int = member.value
in there but to no avail.3 Replies
it's gross, but i've answered my own question. i found the example here: https://docs.modular.com/mojo/manual/traits#generic-structs-with-traits
looks like
List
doesn't support direct iteration, but it does support Python-style accessing. this works:
the list iterator doesn't directly give you the items in the list, it gives you references to the items in the list. To get the actual item you need to index into the reference. References only contain 1 thing so you don't need to actually pass an index.
okay, cool. that'll work. thank you!