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 SAA27685; Mon, 19 Jan 2004 18:46:47 +0100 (MET) 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 SAA27557 for ; Mon, 19 Jan 2004 18:46:46 +0100 (MET) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0JHkjv22243; Mon, 19 Jan 2004 18:46:45 +0100 (MET) Received: from fichte.ai.univie.ac.at (markus@localhost [127.0.0.1]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) with ESMTP id i0JHkhHn003432; Mon, 19 Jan 2004 18:46:43 +0100 Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) id i0JHkeQN003431; Mon, 19 Jan 2004 18:46:40 +0100 Date: Mon, 19 Jan 2004 18:46:40 +0100 From: Markus Mottl To: Richard Jones Cc: Luc Maranget , Ocaml Mailing List Subject: Re: [Caml-list] ANNOUNCE: mod_caml 1.0.6 - includes security patch Message-ID: <20040119174640.GA28829@fichte.ai.univie.ac.at> Mail-Followup-To: Richard Jones , Luc Maranget , Ocaml Mailing List References: <20040116093454.GA23909@redhat.com> <20040119111353.A31726@beaune.inria.fr> <20040119113637.GA30306@redhat.com> <20040119154333.A7394@beaune.inria.fr> <20040119161011.GA10845@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040119161011.GA10845@redhat.com> User-Agent: Mutt/1.4.1i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 extlib:01 passing:01 higher-order:01 argv:01 argv:01 util:01 util:01 endline:01 usr:01 usr:01 ocamlmktop:01 mytop:01 mytop:01 printf:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 19 Jan 2004, Richard Jones wrote: > * Syntactic support for processing lines in a file, ie: > > while (<>) { ... } > > which is an astonishing piece of brevity. It reads all the command line > arguments, opens the files specified and hands them line-at-a-time to > the code inside the while loop. I think ExtLib has some functionality > to do a small part of this. It should be included in the standard > distribution. Opening all files presented on the command line and passing them to some user-specified function can be easily done using higher-order functions, e.g.: let all_lines f = for i = 1 to Array.length Sys.argv - 1 do let ic = open_in Sys.argv.(i) in try while true do f (input_line ic) done with End_of_file -> close_in ic done Putting functions like "all_lines" into a utility module, you can use "#load" to apply it from scripts: #load "util.cmo" open Util let _ = all_lines print_endline I don't see a need for syntactic support. Adding two very short lines to the top of your script (one-time effort) is hardly distracting. > * Syntactic support for regular expression matching / substring extraction. > > (As discussed before.) People often abuse this Perl-feature, because they don't know how to write lexers/parsers using generators, which would sometimes be the better choice. > * No (visible) compilation required. > > #!/usr/bin/perl > > Very useful. There was some discussion before about writing scripts > starting with: > > #!/usr/bin/ocaml You don't need compilation with OCaml if you want to do scripting! All you need to do is create a toplevel using the "-custom"-flag, e.g.: ocamlmktop -custom -o mytop This is required under Unix, because only binary executables can be used for interpretation due to security concerns. Then write a script like this (assuming that mytop is in the same directory - you can place it elsewhere, of course): #!mytop #load "unix.cma" open Unix let _ = Printf.printf "%f\n" (Unix.gettimeofday ()) As you can see, even loading modules (here: Unix) that use shared libraries works like a charm. Btw., what's the reason why "ocaml" is not installed using "-custom" by default? The size of the executables is almost the same, and people could more easily use OCaml for scripting then. > * Certain idiomatic forms, such as: > > statement if condition; > and: statement unless condition; > > which reduce code size. Too much redundancy with control constructs is not a good idea, IMHO. The gain is just too small. > * Absolutely huge library. > > I'm trying to do my bit here by writing libraries, and specifically > with perl4caml which allows you to use Perl libraries with OCaml. A > central CPAN-like resource would still be very useful. I agree that there could be more and better libraries around. But that's true for any language whose programmers want to be lazy. ;-) Regards, Markus -- Markus Mottl http://www.oefai.at/~markus markus@oefai.at ------------------- 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