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 ? > 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. 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
