Browse thread
[Caml-list] ANNOUNCE: mod_caml 1.0.6 - includes security patch
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Markus Mottl <markus@o...> |
| Subject: | Re: [Caml-list] ANNOUNCE: mod_caml 1.0.6 - includes security patch |
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