From: Jon Harrop <jdh30@cam.ac.uk>
To: caml-list@inria.fr
Subject: Re: [Caml-list] help
Date: Fri, 23 Apr 2004 05:17:59 +0100 [thread overview]
Message-ID: <200404230517.59319.jdh30@cam.ac.uk> (raw)
In-Reply-To: <BAY7-F75TvLOrDWSMXQ000055f9@hotmail.com>
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
next prev parent reply other threads:[~2004-04-23 4:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-23 2:31 mohammad siddiqui
2004-04-23 4:17 ` Jon Harrop [this message]
2004-04-23 6:52 ` Jean-Christophe Filliatre
2004-04-23 15:43 ` Brian Hurt
-- strict thread matches above, loose matches on Subject: below --
2004-04-25 16:30 mohammad siddiqui
2004-04-25 1:53 ` mohammad siddiqui
2004-04-25 12:13 ` Jon Harrop
2004-04-25 12:45 ` Henri DF
2004-04-26 19:13 ` Jon Harrop
2004-04-26 22:38 ` Andrew Lenharth
2004-04-25 17:28 ` Matt Gushee
2004-04-25 17:06 ` Jon Harrop
2004-04-25 17:39 ` Matt Gushee
2004-04-26 0:45 ` skaller
2004-04-22 23:34 mohammad siddiqui
2004-04-22 23:57 ` Karl Zilles
2004-04-16 18:04 mohammad siddiqui
2004-04-16 18:59 ` skaller
2004-04-17 0:34 ` Shawn Wagner
2004-04-08 22:57 mohammad siddiqui
2004-04-09 6:56 ` Basile STARYNKEVITCH
2004-04-09 9:04 ` Richard Jones
2002-11-05 12:22 ÀîÒÇ
2002-11-05 13:39 ` Alessandro Baretta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200404230517.59319.jdh30@cam.ac.uk \
--to=jdh30@cam.ac.uk \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox