[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running OCaml scripts from the command line

Thanks for the reply Raphael.

> Also, if you consider using the toplevel. I'd recommend either rlwrap
> or ledit so as to have edit-line capabilities (historic of typed
> lines) or if you are on the emacs side of the war I hear the toplevel
> integration is nice.
Ah great tip! Thanks!

>> On my machine this does not execute in the top level. That merely runs the 
>> code
>> in the file(1) and exits.
Ah, I guess I was a bit confused. What I want is just the code to execute. What 
I am looking for is a quick way to execute my code, without having to compile 
it first.

>> Running "in the top level" is achieved by the #use primitive. (Also, toplevel
>> has two meaning in OCaml: a toplevel definition is a definition not nested 
>> under
>> any scope and *the* toplevel is the interactive read-compile-execute-print
>> loop.)
In that case, I don't really mean the toplevel at all :)

>> That is not true. The code in test2.ml is executed (or at least it is on my
>> machine):
>> raphael ~ $ cat tata.ml
>> print_endline "fooooooooooo"
>> raphael ~ $ ocaml toto.ml tata.ml
>> blah
On my machine:

sjc187n36:test seb$ cat m1.ml 
let hello () = Printf.printf "Hello from m1\n"

sjc187n36:test seb$ cat m2.ml 
let _ = M1.hello ()
print_endline "Hello world\n"

sjc187n36:test seb$ ocaml m1.ml m2.ml 
sjc187n36:test seb$ 


>> You can try ocamlbuild. If your project is simple enough it will make a 
>> binary
>> out of anything.
>> To build a native executable out of the test1.ml, just type:
>> $ ocamlbuild test1.native
>> (replace by test1.byte for the slower but more portable bytecode version.)
>> It should figure out the dependencies if they are in the same directory and 
>> give
>> you a nice executable.
Yes. That is what I have been doing so far, but the builds, even for my small 
projects are rather slow, and really slow down my development process. I want 
to just quickly run my code to see if I have introduced errors, or done 
anything wrong.
Maybe my build is broken, or maybe I am just spoilt by how fast ruby launches. 
Hah, how ironic :D People complain about ruby being slow, but quickly running 
something in OCaml seems to take me way more time :D

Thanks for all the input Raphael!

Hope you are doing well back in France!
Enjoy the cheese and wine :)

All the best,



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.