4 ms·
You mean homogenous instead of heterogenous, right?
by cgopalan 2y ago
You mean homogenous instead of heterogenous, right?
- tomjakubowski 2y agoTo add to this, arrays are also restricted to primitive C types. A Python array object is simply a heap allocated `unsigned long *` or what have you. https://docs.python.org/3/library/array.html https://docs.python.org/3/library/array.html https://github.com/python/cpython/blob/main/Modules/arraymodule.c https://github.com/python/cpython/blob/main/Modules/arraymod... And you can use struct for heterogenous data =) It has a neat DSL for packing/unpacking the data, reminiscent of the "little languages" from classic book The Practice of Programming. Python is actually pretty nice working with binary data. https://docs.python.org/3/library/struct.html https://docs.python.org/3/library/struct.html
- sgarland 2y ago> Python is actually pretty nice working with binary data. It really is! I’ve been working on a project to generate large amounts of synthetic data, and it calls out to C for various shared libraries to do the heavy lifting *. Instead of encoding and decoding back and forth, I can just ship bytes around, and then directly write them out to a file. Saves a lot of time. *: yes, I should just rewrite it into a faster language entirely. I intend to, but for the time being it’s been “how fast can I make Python without anything but stdlib,” as long as you accept ctypes as being included in that definition.
- sgarland 2y agoUgh… yes. Thank you.
- banannaise 2y agoIt would be very funny to have an iterable type where the items are required to contain incompatible types.
- Sohcahtoa82 2y agoSomewhere out there, I'm sure someone could come up with a use case.