caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Adolf Mathias <dolfi@zkm.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] adding an ocaml interpreter to my C program
Date: Thu, 08 Jan 2004 11:40:53 -0500	[thread overview]
Message-ID: <3FFD8815.3060103@zkm.de> (raw)
In-Reply-To: <20040107130741.U5621@demos.bsdclusters.com>

Dear list,

Kip Macy wrote:

>>Also, it only works for bytecode.  (And it only works for compiled
>>code - linking in the toplevel so you can parse ML directly is a
>>different thing entirely).
>>    
>>
>
>
>I didn't read the message closely enough initially. Linking in the
>toplevel is my stated intention. I'd like to be able to use ocaml
>as an application scripting language. This is doable, but not a 2
>minute copy-paste operation as with perl.
>  
>
As Rich said, the first one seems simple, and the second one is an 
entirely different story. I tried to copy some of the toplevel stuff, 
and got the following function working:

let myeval str =
  let lb  = Lexing.from_string str in
  let phr = !Toploop.parse_toplevel_phrase lb in
  ignore(Toploop.execute_phrase true Format.std_formatter phr);;

With it, I can interactively eval strings, like in
#myeval "sin 45.0;;";;
- : float = 0.850903524534118438
- : unit = ()

Hooray, it works. It becomes obvious though that the scope of O'Caml is 
slightly different than that of embeddable scripting languages like Lua, 
where lua_dostring (the equivalent of the above) is a fundamental 
library function, and written in C.

There is one thing that puzzles me though: I can't get access to symbols 
like Parse.toplevel_phrase like it is done in toplevel.ml, but have to 
access it via !Toploop.parse_toplevel_phrase.
Is this a question for the Ocaml beginner's list?

Dolfi

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2004-01-08 10:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-07  9:01 Kip Macy
2004-01-07 13:00 ` Richard Jones
2004-01-07 15:42   ` Kip Macy
2004-01-07 16:04     ` Richard Jones
2004-01-07 16:51       ` Damien Doligez
2004-01-07 21:09   ` Kip Macy
2004-01-08 16:40     ` Adolf Mathias [this message]

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=3FFD8815.3060103@zkm.de \
    --to=dolfi@zkm.de \
    --cc=caml-list@inria.fr \
    /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).