On 18 February 2011 16:20, Chandrashekar Babu <[email protected]>wrote:
> On 18/02/11 3:05 PM, Vinod Parthasarathy wrote: > > >> Any data-structure that goes beyond the simplicity of a String must > >> be mutable irrespective of the programming language (of course with > >> some possible exceptions). > >> > > > > There is no such hard and fast rule. > > Can you provide any example for say - a "linked list" or a "vector" > which should be immutable with a possible use-case scenario ? > Yes, vectors used in mathematical functions in algebraic topology, for instance. They are always immutable. > > > Complex data structures can be made immutable without needing to copy the > > entire structure every time a modification is made. Only those parts that > > actually change need to be copied. The unchanged part is shared between > the > > new and old structures. This ensures that the complexity of algorithms > > remain the same irrespective of the mutability issue. > > You are talking about a Copy-On-Write data structure which is > irrelevant to the actual point. Lists were never designed to > be COW data structures. > But that need not stop you from creating a custom linked list as a COW structure. And I was talking in general about complex data structures. Lists are comparatively simpler structures. Vinod. > > And yes, if mutability of a list hurts, there's always a tuple > as others have quoted - and you can anytime convert a list > to a tuple using the tuple(list) function in python. > > Cheers, > Chandrashekar. > > -- > http://www.chandrashekar.info/ > http://www.slashprog.com/ > > _______________________________________________ > ILUGC Mailing List: > http://www.ae.iitm.ac.in/mailman/listinfo/ilugc > _______________________________________________ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
