-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] implement __getitem__
for ListLiteral
#2141
Comments
I don't think that is a thing. Where would it be useful? |
This, I'm using to implement the code from: https://github.com/python/cpython/blob/main/Lib/tempfile.py#L156-L181 Basically, I'm thinking of a bit solid implementation for tempfile and tempdir just like Python's implementation. |
Should I go ahead with the implementation? |
@kiran-4444 for #2018 I guess you could simply iterate over a list for now, the following code prints all the elements of the list:
I agree that iterating over a ListLiteral is usefull but is not blocking for the other issue |
You should be able to do something like this though: Maybe you could use a regular It might be tricky to promote |
__getitem__
for ListLiteral __getitem__
for ListLiteral
In Python, we can initialize a list with a simple syntax like this: a = [1, 2, 'a'] Mojo offers a similar initialization syntax for a list literal: var a = [1, 2, 'a'] However, there are some key differences between Python lists and Mojo's list literals. Python lists support a wide range of operations, including indexing, slicing, getitem, setitem, and more. In contrast, Mojo's list literals currently lack these features, cannot be iterated over directly, and require a parametric index instead of an argument index. While Mojo does support a List type that provides the necessary functionality for indexing, slicing, and iteration, the List type cannot be initialized using the same syntax as a list literal. It would be great if Mojo's list literals could support the same operations as Python lists or if the List type could be initialized with the list literal syntax and also make sure that mojo listliteral supports nested list like python nested list |
What is the plan for ListLiteral in general? |
Review Mojo's priorities
What is your request?
I see this issue being referred in #100 and few other places, but
__getitem__
isn't still implemented (or at least I wasn't able to access an item using it's index in aListLiteral
).What is your motivation for this change?
I'm trying to work on #2018 and found that I need to iterate through a list of possible env variables that define the temp dirs names. But I'm surprised that I can't access the list items using their indices:
Any other details?
I'd like to implement this if someone else isn't already working on this.
The text was updated successfully, but these errors were encountered: