Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Kontra, Gergely <kgergely@m...>
Subject: [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs

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

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

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


+-[Kontra, Gergely @ Budapest University of Technology and Economics]-+
|         Email:,          |
|  URL:    Mobile: (+36 20) 356 9656     |
+-------"Olyan langesz vagyok, hogy poroltoval kellene jarnom!"-------+
Magyar php mirror es magyar php dokumentacio:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: