From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA14107; Thu, 26 Sep 2002 17:50:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA14087 for ; Thu, 26 Sep 2002 17:50:05 +0200 (MET DST) Received: from mlabdial.hit.bme.hu (mlabdial.hit.bme.hu [152.66.248.201]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8QFo4D24847 for ; Thu, 26 Sep 2002 17:50:04 +0200 (MET DST) Received: from localhost (kgergely@localhost) by mlabdial.hit.bme.hu (8.11.6/8.11.6) with ESMTP id g8QFo3K19960 for ; Thu, 26 Sep 2002 17:50:03 +0200 Date: Thu, 26 Sep 2002 17:50:03 +0200 (CEST) From: "Kontra, Gergely" To: caml-list@inria.fr Subject: [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-2 Content-Transfer-Encoding: 8BIT Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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