#Why doesn't this work for creating lists?

12 messages · Page 1 of 1 (latest)

fresh path
#
fn main() -> None:
 var any_list = List[Int](range(1, 10_000_000))
ashen turret
#

We don't have language support to implement this constructor the right way (no trait with associated types), and no one feels compelled enought to implement the overloads for range.

fresh path
#

I don't understand why they say that Mojo is a super set of Python. It feels like another completely different language outside of the Python ecosystem.

brazen jetty
fresh path
#

I understand, it is a goal for the future.

ashen turret
#

Mojo is trying to recreate the everyday Python experience on a typed foundation, and there's much left to be built.

ashen turret
desert dragon
#

you should be able to write this pretty easily too, since you’d just need to iterate over the range and set the values

ashen turret
brazen jetty
# ashen turret At least until: https://github.com/modularml/mojo/pull/2949

That is closed because having multiple structs allows for specialization and for open ended ranges to be passed in registers. The solution is to have a Range trait that allows you to use them as iterators like Rust does, except ideally delay the iteration as long as possible since it can be iterated at comptime and expanded for fixed-length ranges, allowing for unrolling.

ashen turret
#

I'd agree that in the current stage, it's better implemented as three structs. But I don't believe this problem is fundamental: I don't think you can argue that we should expect reversed(range(n)) being slower as range(n) since the former uses the most general range structure. Also, a single iterator trait will cause the same specialisation problem if specialisation is indeed the problem, we may still need something like SizedIterable like in Swfit or c++.