file13
12-12-2002, 11:31 AM
i was playing with mod_ocaml:
http://www.slacky.de/docs/projects/mod_ocaml/
and thought i'd share some examples and findings. briefly it's kinda like php where you put ocaml statement directly in html.
the install was easy. pretty much compiled the .c file with apxs, stuck it into the apache libexec dir and added 2 lines to the httpd.conf. a restart later and it was working.
here's an example page:
http://www.qlippoth.com/test_mod_ocaml.ocml
ignore the "mod_ocaml Parser Warning:" at the top because i'm too lazy to do 2 seperate pages at the moment (i.e. do it properly) for the get request...just a quick hack to play with it.... ;)
here's the source for "test_mod_ocaml.ocml"
<html>
<body>
<?ocml
let say_hi ?(name = "Apache") () = Printf.printf ("Hi %s!\n") (name);;
?>
Test Mod_Ocaml:
<?ocml Printf.printf ("This is generated by the OCAML interpreter.");; ?>
Test a function:
<?ocml say_hi ();; ?>
Test a get function:
<form action="test_mod_ocaml.ocml" method="post">
Enter your name:
<input type="text" name="name">
<input type="submit" name="submit" value="Enter">
</form>
You entered the name:
<?ocml
if "$name" = "*undef*" then
say_hi ()
else
say_hi ~name:"$name" ();;
?>
Test a recursive function:
<?ocml
let rec count_down x =
if x >= 1 then
begin
Printf.printf "%d
" x;
count_down (x - 1)
end
;;
count_down 10;;
?>
</body>
</html>
overall it seems pretty nifty for dynamic pages. given, i'm not the biggest web hacker/dynamic content guy, but this may persuade me to start.... :D
http://www.slacky.de/docs/projects/mod_ocaml/
and thought i'd share some examples and findings. briefly it's kinda like php where you put ocaml statement directly in html.
the install was easy. pretty much compiled the .c file with apxs, stuck it into the apache libexec dir and added 2 lines to the httpd.conf. a restart later and it was working.
here's an example page:
http://www.qlippoth.com/test_mod_ocaml.ocml
ignore the "mod_ocaml Parser Warning:" at the top because i'm too lazy to do 2 seperate pages at the moment (i.e. do it properly) for the get request...just a quick hack to play with it.... ;)
here's the source for "test_mod_ocaml.ocml"
<html>
<body>
<?ocml
let say_hi ?(name = "Apache") () = Printf.printf ("Hi %s!\n") (name);;
?>
Test Mod_Ocaml:
<?ocml Printf.printf ("This is generated by the OCAML interpreter.");; ?>
Test a function:
<?ocml say_hi ();; ?>
Test a get function:
<form action="test_mod_ocaml.ocml" method="post">
Enter your name:
<input type="text" name="name">
<input type="submit" name="submit" value="Enter">
</form>
You entered the name:
<?ocml
if "$name" = "*undef*" then
say_hi ()
else
say_hi ~name:"$name" ();;
?>
Test a recursive function:
<?ocml
let rec count_down x =
if x >= 1 then
begin
Printf.printf "%d
" x;
count_down (x - 1)
end
;;
count_down 10;;
?>
</body>
</html>
overall it seems pretty nifty for dynamic pages. given, i'm not the biggest web hacker/dynamic content guy, but this may persuade me to start.... :D