On Thu, 15 Dec 2011 16:54:16 -0500 Ned Batchelder firstname.lastname@example.org wrote:
On 12/15/2011 4:24 PM, Ethan Furman wrote:
Python is a dynamic language -- why can't it have dynamic structs?
I honestly don't know how to interpret this.
I do. Ethan is incorrectly trying to turn a similarity - that both Python tuples and C structs are collections of heterogeneous data - into an analogy. They aren't analogs, as that's pretty much the only similarity.
If you really want a dynamic tuple - a dynamic collection of heterogeneous data accessed by an index - use a list. That was standard practice in LISP-like languages for a long time. But Python (and most modern LISPs) has better tools for such.
For instance, the proper analog for a C struct in Python is the class. You provide definitions of them both along with names for their heterogeneous components. You create instances of them both that can assign different values to those components. The components are properly accessed by name. There are probably other similarities.
There are a number of differences as well. Most notably, instances of classes are dynamic. You can change, and even add and delete, components dynamically.
So Python already has a dynamic struct. You just have to get the analogies right.