* [Caml-list] Really confused - repost
@ 2003-04-04 0:57 Ryan Bastic
2003-04-04 2:27 ` Matt Gushee
2003-04-04 3:21 ` Karl Zilles
0 siblings, 2 replies; 4+ messages in thread
From: Ryan Bastic @ 2003-04-04 0:57 UTC (permalink / raw)
To: caml-list
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, 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??
Thanks
-Ryan
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Really confused - repost
2003-04-04 0:57 [Caml-list] Really confused - repost Ryan Bastic
@ 2003-04-04 2:27 ` Matt Gushee
2003-04-04 3:21 ` Karl Zilles
1 sibling, 0 replies; 4+ messages in thread
From: Matt Gushee @ 2003-04-04 2:27 UTC (permalink / raw)
To: caml-list; +Cc: caml-list
On Thu, Apr 03, 2003 at 07:57:08PM -0500, Ryan Bastic wrote:
>
> 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, 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??
Sure. What you are doing here
!groups.(!q) := ar;
is trying to assign an array ref as the *value* of a ref. In other
words, you're trying to replace something like:
[|"Phred","Sue"|]
with
{ contents = [|"Karla","Hans"|] }
which is obviously a different type ( string array ref instead of string
array). I think what you want to do is
!groups.(!q) <- ar;
The revised version is replacing an array element (which is a ref) with
a new ref.
--
Matt Gushee When a nation follows the Way,
Englewood, Colorado, USA Horses bear manure through
mgushee@havenrock.com its fields;
http://www.havenrock.com/ When a nation ignores the Way,
Horses bear soldiers through
its streets.
--Lao Tzu (Peter Merel, trans.)
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Really confused - repost
2003-04-04 0:57 [Caml-list] Really confused - repost Ryan Bastic
2003-04-04 2:27 ` Matt Gushee
@ 2003-04-04 3:21 ` Karl Zilles
2003-04-04 3:28 ` Karl Zilles
1 sibling, 1 reply; 4+ messages in thread
From: Karl Zilles @ 2003-04-04 3:21 UTC (permalink / raw)
To: rbastic; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Really confused - repost
2003-04-04 3:21 ` Karl Zilles
@ 2003-04-04 3:28 ` Karl Zilles
0 siblings, 0 replies; 4+ messages in thread
From: Karl Zilles @ 2003-04-04 3:28 UTC (permalink / raw)
To: Karl Zilles; +Cc: rbastic, caml-list
Karl Zilles wrote:
> In any case, this looks like a homework assignment, so I'll just give
> you some general advice.
5) You can write
printf "something here"
instead of
fprintf stdout "something here"
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-04-04 3:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-04 0:57 [Caml-list] Really confused - repost Ryan Bastic
2003-04-04 2:27 ` Matt Gushee
2003-04-04 3:21 ` Karl Zilles
2003-04-04 3:28 ` Karl Zilles
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox