Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] OCaml as fancy calculator...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Max Skaller <skaller@m...>
Subject: Re: [Caml-list] OCaml as fancy calculator...
Oliver Bandel wrote:

> If I write some often-needed mathematical routines,
> so that it can be used with file-based OCaml-programs
> for compilation, how can I use such files (or the compiled
> byte-code or binaries) for interactive sessions with
> ocaml?
> 
> Is this the first step to use the module system?

	Yes. First, create a file, say

	my_routines.ml

and then compile it to bytecode:

	ocamlc my_routines.ml

Note that you have just created a module

	My_routines

Note the Capital letter onon the module name and the
lower case letter on the filename.

Now you can use it in the top level, in one or two steps.
First, you must say

	#load "my_routines.cmo"

Now you can say:

	My_routines.sin 1.2;;

and you'll get your routine 'sin' from module My_routines
called: thats the 'sin' in the file 'my_routines.ml'.
You can avoid typing the prefix 'My_routines' by saying

	open My_routines;;

then

	sin 1.2;;

but you should note that this will hide any other routine 'sin'
that's hanging around.

If you want to script a series of calculations in a file

	my_calcs.ml

you can say

	#use "my_calcs.ml"

Note that this is like a C #include: it compiles and executes as it
goes.
Whereas the #load is loading _already_ compiled code.

It's a good idea to run the top level 'ocaml' with 

	ledit ocaml

if you like keyboard editing. You'll need to download and build ledit
first. [Perhaps this will get built into the top level one day :-]

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix  http://felix.sourceforge.net
Literate Programming tool Interscript     
http://Interscript.sourceforge.net
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr