Seeking Guidance and Best Practices for Lists and Tuples in Mojo Language
Hello Wonderful Mojo Community!
I'm excited to embark on my journey with the Mojo language and am particularly interested in developing datetime and strings libraries. As a newcomer, I'm eager to learn and contribute to this vibrant community.
However, I've encountered a bit of a hurdle while working with lists and tuples. Unlike Python, where I can easily access items in a list or tuple, in Mojo, I receive an error stating:
it does not implement the '__getitem__'/'__setitem__' or '__refitem__' methods.
I'm keen to understand the best practices for handling lists and tuples in Mojo. Could anyone provide guidance or share their experiences on how to navigate this? I'm looking forward to your insights and tips to enhance my understanding and skills in Mojo.
Thank you all in advance for your support and assistance!25 Replies
Congrats @Aamir, you just advanced to level 1!
you're probably used to using square brackets on python's lists, for mojo's ListLiteral you'll need to use the .get method https://docs.modular.com/mojo/stdlib/builtin/builtin_list.html#get
or alternatively, you might be able to just use a dynamicvector if your items in the list are all the same type
Yeah, I had tried that. However, I dont know the right way to invoke
get
function. It didn't work for me!![No description](https://cdn.answeroverflow.com/1208836519830233108/image.png)
Is there any book or guided language tour that I can try?
Also, when I tried to import DynamicVector, I get this error!
![No description](https://cdn.answeroverflow.com/1208837438944845945/image.png)
I am using
mojo 0.7.0 (af002202)
on windows Ubuntu WSL.I need to pass, get value at the given
'i
index.![No description](https://cdn.answeroverflow.com/1208986968751611914/image.png)
About Vector import. I followed this!
![No description](https://cdn.answeroverflow.com/1208987337527136267/image.png)
After importing the DynamicVector from collections. That error went away, but it started crashing again!
![No description](https://cdn.answeroverflow.com/1208987854047281192/image.png)
Compiler is crashing now!
Is this language stable? I am not able to move an inch. There should be proper guided language tour with documentations. The way Go did.
it's fairly common to have the parser crashing, remember that this language is pre 1.0, you are helping with early testing
I see!
I understand, no worries
while it may take some fiddling to get the dynamicvector working, you're on the right path to getting the program working if you need to index into a collection with a value from a variable
But, after adding dynamic vector, I can't move ahead, due to parser crash. How do you guyw deal with such issues.