Should we fuse Python's array class and mojo's DynamicVector's struct?

They are extremely similar. Here is the documentation for array: https://docs.python.org/3/library/array.html Here is the documentation for DynamicVector: https://docs.modular.com/mojo/stdlib/utils/vector.html#dynamicvector With just a few more attributes and methods, Python's array could become a DynamicVector. If Mojo wants to be a good member of the Python family, maybe we should not reinvent what's already in the stdlib.
Python documentation
array — Efficient arrays of numeric values
This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, e...
3 Replies
Alex Kirchhoff
Alex Kirchhoff•14mo ago
Mojo's DynamicVector is closer to Python's list -- a better equivalent to Python's array is Mojo's Tensor. (DynamicVectors are resizeable dynamically; Tensor shapes are fixed at creation time.) That said, Mojo's standard library is in a very early state right now, and is changing rapidly. In particular, many useful things are not possible yet because traits are not ready yet. As the language develops further, we expect it will get closer to Python.
gabrieldemarmiesse
gabrieldemarmiesseOP•14mo ago
Great! Thanks for the detailed answer, though it seems there is a slightly misunderstanding, Python's array are resizable dynamically:
>>> import array
>>> a = array.array("i", [1, 2])
>>> a.append(3)
>>> a
array('i', [1, 2, 3])
>>> import array
>>> a = array.array("i", [1, 2])
>>> a.append(3)
>>> a
array('i', [1, 2, 3])
Though of course that doesn't invalidate your answer. I'll be waiting for traits 🙂
ModularBot
ModularBot•14mo ago
Congrats @gabrieldemarmiesse, you just advanced to level 3!
Want results from more Discord servers?
Add your server