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 QAA26787; Tue, 7 Aug 2001 16:33:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA26780 for ; Tue, 7 Aug 2001 16:33:20 +0200 (MET DST) Received: from localhost.localdomain (cartman23.zip.com.au [61.8.20.151]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f77EXG521615 for ; Tue, 7 Aug 2001 16:33:17 +0200 (MET DST) Received: from maxtal.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id AAA15155; Wed, 8 Aug 2001 00:32:42 +1000 Message-ID: <3B6FFC09.1BB84969@maxtal.com.au> Date: Wed, 08 Aug 2001 00:32:41 +1000 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Oliver Bandel CC: caml-list@inria.fr Subject: Re: [Caml-list] OCaml as fancy calculator... References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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