support creation of list via multiplication operator #48
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/nac3#48
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
currently fails with
This requires modification of the type system. The current implementation separates list and objects, so lists cannot have methods. Maybe we would need to treat lists as objects.
This is a very common way of creating large lists (is there any other way?) so we definitely need to support that.
Two ways to do this. We can either support this via modifying the type checking module (would break quite a lot of tests and other code...) or use a special builtin function to do it. The second option would be much simpler to implement for now.
Maybe something like this:
What do you think?
The
repeat
function is fine but it should be called something more specific. Maybenew_list
or similar. It could be simply called asnew_list(1, 100)
without the[]
.For the syntactic sugar, do an AST match-pattern-and-replace pass before typechecking? That pass could also handle things like
int64(round())
->round64()
.new_list(T, int) -> [T]
would not support things like[1, 2, 3] * 100
, although I'm not sure if users want this feature.For syntactic sugar, I think the best we can do is just support thing like
[...] * ...
. Things more complicated likeis not supported unless we modify the type system.
Those restrictions are fine IMHO.
suddenly remember that the user should be able to use
[a for _ in range(x)]
. Do we still need the workaround for now?I suppose only
range(int32)
is to be supported as iterator there.Can this be implemented quickly and without runtime performance issues?
This may need some time... I'm thinking about how to deal with
range
without a range type for now.I think we can optimize the implementation to make it fast.
Implemented with list comprehension.