From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id FAA22512; Fri, 4 Apr 2003 05:16:27 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA22159 for ; Fri, 4 Apr 2003 05:16:25 +0200 (MET DST) Received: from woodstock.1969.ws (64-215-156-42.eosinc.net [64.215.156.42]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id h343GN921342 for ; Fri, 4 Apr 2003 05:16:24 +0200 (MET DST) Received: (qmail 24032 invoked from network); 4 Apr 2003 02:58:52 -0000 Received: from karl.1969.ws (HELO 1969.ws) (10.3.2.15) by woodstock.1969.ws with SMTP; 4 Apr 2003 02:58:52 -0000 Message-ID: <3E8CFA43.6040106@1969.ws> Date: Thu, 03 Apr 2003 19:21:39 -0800 From: Karl Zilles Organization: 1969 Communications, Inc. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: rbastic@gis.net CC: caml-list@inria.fr Subject: Re: [Caml-list] Really confused - repost References: <3e8cd864.72ae.19774@gis.net> In-Reply-To: <3e8cd864.72ae.19774@gis.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; caml-list:01 foobar:01 readline:01 shorter:01 arrays:01 mutable:01 int:01 groups:01 binding:03 string:03 wrote:03 variable:03 iter:03 data:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Ryan Bastic wrote: > Hey all, > Just reread my initial message and realized how incomprehensible it > was. > > Basically, what I'm trying to do is on display at: > http://malander.undrgnd.net/foobar/students.ml > > it should be fairly clear what i'm trying to do... i want to split up > the vector > of student names into varying-sized groups, It looks like all your groups are the same size. >preferably using arrays of > arrays, but any other data structure will do :-) > > if you try executing students.ml, you'll see on line 68 there is a > problem... > > can anyone point me in the direction as to what's going on?? In any case, this looks like a homework assignment, so I'll just give you some general advice. 1) Please use descriptive variable names. Instead of calling a binding "x" you might use "number_of_groups". Everyone will love you. 2) Not everything has to be a reference. If it doesn't change once it is assigned, then a simple let statement will do. e.g. let number_of_students = Array.length students in let group_size = int_of_string (readline ()) in let number_of_groups =(number_of_students + group_size - 1)/group_size in etc... 3) Arrays are mutable. You don't need to make arrays of references in order to change the contents of an array. let tmp = Array.make 1 "" in let groups = Array.make number_of_groups tmp in ... let ar = Array.make !group_size "" in .. groups.(!current_group) <- ar; 4) We're programming in a functional language. I can tell you've learned C. Those are the bad old days. If you want to iterate over all the students, you should use: Array.iter (fun student -> do something here; ) students; instead of: let n = Array.length students - 1 in let i = ref 0 in while !i <> n do do something here with students.(!i); done; Not only because it's shorter, but because you're less likely to make a mistake (hint, hint). If you need then array index, look at the iteri function. Good Luck! ------------------- 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