From: Karl Zilles <zilles@1969.ws>
To: rbastic@gis.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Really confused - repost
Date: Thu, 03 Apr 2003 19:21:39 -0800 [thread overview]
Message-ID: <3E8CFA43.6040106@1969.ws> (raw)
In-Reply-To: <3e8cd864.72ae.19774@gis.net>
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
next prev parent reply other threads:[~2003-04-04 3:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-04 0:57 Ryan Bastic
2003-04-04 2:27 ` Matt Gushee
2003-04-04 3:21 ` Karl Zilles [this message]
2003-04-04 3:28 ` Karl Zilles
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=3E8CFA43.6040106@1969.ws \
--to=zilles@1969.ws \
--cc=caml-list@inria.fr \
--cc=rbastic@gis.net \
/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