Accueil     À propos     Téléchargement     Ressources     Contactez-nous

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

[Caml-list] small_exercise
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2002-11-29 (18:48) From: Pierre Weis Subject: Re: [Caml-list] small exercise
```> altavillasalvatore@libero.it wrote:
> > Hi all,
> >
> > I do not succeed to develop the following exercise:
> > I have need of your aid.
> >
> >
> >
> > input:  string    "1.15.120.13.43.35.340.190.0"
> >
> > output: int array=  [| 1; 15; 120; 13; 43; 35; 340; 190; 0; |]
> >
> >   : string -> int array
> >
> >
> > Regards.
[...]
> Just a hint look at the documentation of the following functions:
>
> module        | function
> ------------------------------
> str           | split
> list          | map
> pervasives    | int_of_string
> array         | of_list
>
> The answer fits on one (long) line.
> --
> Christophe Raffalli

I guess, you forgot the most appropriate module for the exercicise: Scanf.

Indeed, scanning the given input string to obtain the expected vector
only using Scanf.scanf is interesting and not completely trivial.

that can input vectors with elements of any simple basic type (say
bool, int, string, char, float). Define a string reader via partial

Last but not least could be: generalize (if necessary) the polymorphic
matrices of floating point numbers. Discuss the use of Scanf in place
of a combination of modules Str, List, Pervasives, Array, ...

Mmm. A trivial exercicise could show up to be interesting afterwards :)

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/

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

```