From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1SISJo4030898 for ; Mon, 28 Feb 2011 19:28:19 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjIHAMN3a01c8w3B/2dsb2JhbACYM48JvCOFYQQ X-IronPort-AV: E=Sophos;i="4.62,241,1297033200"; d="scan'208";a="88851543" Received: from dangi.happyleptic.org (HELO dangi) ([92.243.13.193]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 28 Feb 2011 19:28:14 +0100 Received: from extranet.securactive.org ([82.234.213.170] helo=ccellier.rd.securactive.lan) by dangi with esmtp (Exim 4.72) (envelope-from ) id 1Pu7pY-0002OL-BF for caml-list@inria.fr; Mon, 28 Feb 2011 19:28:24 +0100 Received: from rixed by ccellier.rd.securactive.lan with local (Exim 4.72) (envelope-from ) id 1Pu7pN-0002T8-LQ for caml-list@inria.fr; Mon, 28 Feb 2011 19:28:13 +0100 Date: Mon, 28 Feb 2011 19:28:13 +0100 From: rixed@happyleptic.org To: caml-list@inria.fr Message-ID: <20110228182813.GA5462@ccellier.rd.happyleptic.org> References: <20110226214403.GA20532@yeeloong.happyleptic.org> <20110227120027.GA3544@aurora> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110227120027.GA3544@aurora> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: [Caml-list] Calling the toplevel from the toplevel > Actually you can, you just have to make sure that .cmi files are > available in the search paths of the toplevel when you run your > application. Yes, it works now. AFAICT the cmi have always been available, but anyway... > > - I cannot let the user uses the toplevel directives "use" and "load" > > because both writes into stdout whatever the formatter passed to > > Toploop.execute_phrase (for "use" this is easily solvable by shadowing > > the toplevel implementation by another one that call Toploop.use_file > > with my own formatter, but for "load" I would have to copy a lot of > > code from topdirs.ml > > Why not use Topdirs.dir_load with a custom formatter ? Because I had not noticed that these functions were available. This is handy. So I end up with something similar to you, except I don't shadow that much directives (only those I know and use regularly, and I'm not very experienced with the toplevel to say the least). > If you are interested, i started some time ago an emacs-like editor > which can run in both curses and gtk mode and which integrates a > toplevel. Haha!, this is the very same reason why I was asking these questions. Except that my project is just a small pet project consisting only of less than 1k LOC, and I hope it will stay that way. I'm just used to mix C and scheme to use the scheme repl to manipulate the running C app and wanted to know how easy/hard it would be to have the same "hackability" with Ocaml. > I add to face the same problems. I solved them by using > Toploop.execute_phrase directly and redefining all directives. I've seen. We use very similar approach. The funny thing is that when I started I was convinced that it was not possible to call the Toploop evaluator from within itself, and tried many other solutions, until I noticed that topfind.ml actually does this to enrich the toplevel directives. > Also another problem i had is that Toploop.execute_phrase does not > prints errors on the given formatter but raises an exception instead, > and the printer used in Toploop.loop (Errors.report_error) is in the > module Errors for which the cmi is not available. I give the exception to Toploop.print_exception_outcome : let top_eval cmd = let cmd = Rope.to_string cmd in Log.p "Executing '%s'" cmd ; try let l = Lexing.from_string cmd in let ph = !Toploop.parse_toplevel_phrase l in Toploop.execute_phrase true self#formatter ph with exn -> Toploop.print_exception_outcome self#formatter exn ; false in but the exceptions are only pretty printed to a depth of 1, further values being replaced by "_", so it's far from perfect. > I used a hack which > consists on parsing the output of Toploop.use_silently (file > peps_top.ml, function eval_command). Ooooh, I see! I'd never come up with this idea. BTW, do you have any future plan for peps?