caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs
@ 2002-09-26 15:50 Kontra, Gergely
  2002-09-27  8:01 ` Maxence Guesdon
  2002-09-27 14:50 ` Florian Hars
  0 siblings, 2 replies; 11+ messages in thread
From: Kontra, Gergely @ 2002-09-26 15:50 UTC (permalink / raw)
  To: caml-list

Hi!

First sorry for my previous post, I don't read the whole thread before
posting.

Yesterday (half the night) I spent my time writing an extremely simple
program, which recursively change the text .xml to .html (actually the
links, but this is a very simple program, so I didn't parse the html) in
all html files in the given directory (and in the subdirectories).
Before I wrote the same in ruby. To better clear ocaml, I put the
corresponding statements to the same row in a table.

One point was ocaml is really obscure is the file reading: it needed to
wrap the line-reading in an infinite loop, and this loop is ended via an
exception. I think End_of_file is not an exception, it is just an event.

I'm sure this whole thing can be solved with a nice lazy list with the
apply method, and should ocaml follow this way.

Suggestions? Implementations? Will it be in the next release?

Another annoying problem (maybe it is in the docs...), but I cannot find
a function, which checks, whether a string can match a regexp, and
return true or false. Search_forward, again, I think should be return an
option, and not trowing an exception.

BTW what about the many labelled-not labelled stuff. As matters
stand: it look a bit caothic, I think it is the beginning of adopting
the libraries to the new label functionality.

But the thing most of the time I was spending with was the actual ocaml
syntax. I cannot feel the precedences, where to put ;-s and ;;-s.

If anyone can (constructively) criticise my programming style, please
send me your suggestions!

The program mentioned above:
open Unix
open Str

let rec replace what =
  if (stat what).st_kind==S_DIR then (
    print_string (what^" is a directory, so entering...\n");
    let dir=opendir what in
    try
      while true do
        let item=readdir dir in
        print_endline("Considering replacing in "^item);
        match item with
        | "."->()
        | ".." -> ()
        | _ -> replace (what ^ "\\" ^ item)
      done
    with
      End_of_file->()
    )
  else
    let tempname=what^".bak" in
    if (Str.last_chars what 5) <> ".html" then
      print_endline(what^" is not a html file, so skipping")
    else
       (print_endline("Renaming "^what^" to "^tempname);
      Sys.rename what tempname;
      let w=open_out what in
      let r=open_in tempname in
      try
        while true do
          output_string w ((global_replace (regexp
"\\.xml") ".html" (input_line r))^"\n")
        done
      with End_of_file -> close_in r;close_out w;
      Sys.remove tempname);;

 replace "tutorial" (* well, it is hard-coded, but enough for me*)

Gergő

+-[Kontra, Gergely @ Budapest University of Technology and Economics]-+
|         Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |
|  URL:   turul.eet.bme.hu/~kgergely    Mobile: (+36 20) 356 9656     |
+-------"Olyan langesz vagyok, hogy poroltoval kellene jarnom!"-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

-------------------
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] 11+ messages in thread
[parent not found: <Pine.LNX.4.44.0209300427310.1961-100000@home.oyster.ru>]

end of thread, other threads:[~2002-09-30  1:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-26 15:50 [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs Kontra, Gergely
2002-09-27  8:01 ` Maxence Guesdon
2002-09-27  8:14   ` Xavier Leroy
2002-09-27 10:29     ` Kontra, Gergely
2002-09-27 14:50 ` Florian Hars
2002-09-27 15:07   ` Maxence Guesdon
2002-09-27 17:06     ` Kontra, Gergely
2002-09-27 18:22       ` Tim Freeman
2002-09-27 22:27     ` malc
2002-09-28  9:30   ` [Caml-list] stdlib req - iter and fold on channels Stefano Zacchiroli
     [not found] <Pine.LNX.4.44.0209300427310.1961-100000@home.oyster.ru>
2002-09-30  1:19 ` [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs Alessandro Baretta

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