[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jdh30@c...> |
| Subject: | Re: [Caml-list] help |
On Friday 23 April 2004 3:31 am, mohammad siddiqui wrote: > I already made it mutable. words is an array of structure called "word". > If I try to change the value as you told it changes tha values of all the > elements of array "words". Thanks for your help in advance. > > Mohammad S Siddiqui. I haven't actually done that sort of thing myself but asking ocamlbrowser for the interface information on Array.make gives: >>>>> external make : int -> 'a -> 'a array = "make_vect" (** [Array.make n x] returns a fresh array of length [n], initialized with [x]. All the elements of this new array are initially physically equal to [x] (in the sense of the [==] predicate). Consequently, if [x] is mutable, it is shared among all elements of the array, and modifying [x] through one of the array entries will modify all other entries at the same time. Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. If the value of [x] is a floating-point number, then the maximum size is only [Sys.max_array_length / 2].*) <<<<< "Array.create" is a depricated alias for "Array.make", BTW. So if you're using either "Array.make" or "Array.create" to build your array then you're creating an array filled with references to the same thing. Does that answer your question? Personally, I tend to build up a list and then convert it into an array using "Array.of_list". I guess the question is: are you creating an unecessary level of indirection by making the type of the elements in your array mutable when an array element is itself already mutable? If you're still having trouble with your data structures then I'll run through it with you off the mailing list... Cheers, Jon. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners