caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@maxtal.com.au>
To: Oliver Bandel <oliver@first.in-berlin.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] OCaml as fancy calculator...
Date: Wed, 08 Aug 2001 00:32:41 +1000	[thread overview]
Message-ID: <3B6FFC09.1BB84969@maxtal.com.au> (raw)
In-Reply-To: <Pine.LNX.3.95.1010805110027.163A-100000@first.in-berlin.de>

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


  parent reply	other threads:[~2001-08-07 14:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-05  9:16 Oliver Bandel
2001-08-05 11:06 ` Pixel
2001-08-05 15:15   ` Oliver Bandel
2001-08-05 19:36     ` Pixel
2001-08-07 14:32 ` John Max Skaller [this message]
     [not found]   ` <20010807171614.B1646@hars>
2001-08-07 17:34     ` [Caml-list] Re: ledit (was: OCaml as fancy calculator...) Daniel de Rauglaudre
2001-08-09  7:21       ` Florian Hars
2001-08-09  7:30         ` Laurent Chéno
2001-08-09  8:02         ` Ari Heitner
2001-08-09  8:37         ` Sven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B6FFC09.1BB84969@maxtal.com.au \
    --to=skaller@maxtal.com.au \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).