caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Virgile Prevosto <virgile.prevosto@m4x.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] laconical input from a file for arrays and/or matrices
Date: Mon, 2 Feb 2004 15:20:20 +0100	[thread overview]
Message-ID: <20040202152020.5bd2723f.virgile.prevosto@m4x.org> (raw)
In-Reply-To: <401E2D08.3080406@stratos-ad.com>

:

Le lundi 02 février, à 11h57 +0100,
samsaga2 a écrit:

> let output_matirx m = output_value stdout m
> let input_matrix () = input_value stdin
> 
> But no compatible with c++ files :-P
> 
> Khamenia, Valery wrote:
> >  here goes my usual way to input ASCII matrices from file in C++:

# let x = Array.make_matrix 1 1 3 in output_value stdout x;;
¦¾C
- : unit = ()

I doubt that we can speak of ASCII matrices in that case ;-)

Anyway, it's not so difficult to obtain a code fragment close to the
C++ one, thanks to the Array and Scanf modules: 

(* CAML version. *)
let input_matrix () = 
  let m = read_int () in
  let n = read_int () in
  let matrix = Array.make_matrix m n 0. in
    for i = 0 to (m - 1)  do
      for j = 0 to (n -1) do
          matrix.(i).(j) <-  Scanf.scanf "%f " (fun x -> x)
      done
    done;
    matrix;;
val input_matrix : unit -> float array array = <fun>

Of course, you'll have to adapt the formatting instruction of scanf to
your datas (the main problem here is that scanf expects to fins a blank
after each entry, which means that your file must end with a newline or
a space).

-- 
E tutto per oggi, a la prossima volta
Virgile

-------------------
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


  reply	other threads:[~2004-02-02 14:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-02 10:42 Khamenia, Valery
2004-02-02 10:57 ` samsaga2
2004-02-02 14:20   ` Virgile Prevosto [this message]
2004-02-02 14:36 ` Richard Jones
2004-02-02 15:54 ` Issac Trotts

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=20040202152020.5bd2723f.virgile.prevosto@m4x.org \
    --to=virgile.prevosto@m4x.org \
    --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;
as well as URLs for NNTP newsgroup(s).