From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A877C7F890 for ; Sat, 29 Mar 2014 12:04:41 +0100 (CET) Received-SPF: PermError (mail3-smtp-sop.national.inria.fr: cannot correctly interpret sender authenticity information from domain of alan.schmitt@polytechnique.org) identity=pra; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=cqEv=Y6=polytechnique.org=alan.schmitt@bounces.m4x.org"; x-sender="alan.schmitt@polytechnique.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of SRS0=cqEv=Y6=polytechnique.org=alan.schmitt@bounces.m4x.org designates 129.104.30.34 as permitted sender) identity=mailfrom; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=cqEv=Y6=polytechnique.org=alan.schmitt@bounces.m4x.org"; x-sender="SRS0=cqEv=Y6=polytechnique.org=alan.schmitt@bounces.m4x.org"; x-conformance=sidf_compatible; x-record-type="spf2.0" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@mx1.polytechnique.org designates 129.104.30.34 as permitted sender) identity=helo; client-ip=129.104.30.34; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="SRS0=cqEv=Y6=polytechnique.org=alan.schmitt@bounces.m4x.org"; x-sender="postmaster@mx1.polytechnique.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArMBAE2nNlOBaB4inGdsb2JhbABZyC8WDgEBAQEBCAsJCRQogiUBAQEDASdSBQsLDhMaCw8BBCghE4dxCATRVxaTKASsdIFA X-IPAS-Result: ArMBAE2nNlOBaB4inGdsb2JhbABZyC8WDgEBAQEBCAsJCRQogiUBAQEDASdSBQsLDhMaCw8BBCghE4dxCATRVxaTKASsdIFA X-IronPort-AV: E=Sophos;i="4.97,756,1389740400"; d="scan'208";a="54601610" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 29 Mar 2014 12:04:41 +0100 Received: from top (cbg35-2-78-242-14-140.fbx.proxad.net [78.242.14.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTPSA id CEAA21408EEF4; Sat, 29 Mar 2014 12:04:39 +0100 (CET) From: Alan Schmitt To: Jeremie Dimino Cc: OCaml Mailing List In-Reply-To: (Jeremie Dimino's message of "Mon, 24 Mar 2014 14:47:30 +0000") Date: Sat, 29 Mar 2014 12:02:57 +0100 Message-ID: References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) MIME-Version: 1.0 Content-Type: text/plain X-AV-Checked: ClamAV using ClamSMTP at svoboda.polytechnique.org (Sat Mar 29 12:04:40 2014 +0100 (CET)) X-Spam-Flag: No, tests=bogofilter, spamicity=0.002682, queueID=158E21408EEF7 X-Org-Mail: alan.schmitt.1995@polytechnique.org Subject: Re: [Caml-list] ocaml toplevel: is it possible to separate what is sent on stdout from the answers from the toplevel? Hello Jeremie, Jeremie Dimino writes: > The best way is to create a custom toplevel and map the replies. > > "val x : int = 3" is printed using [Toploop.print_out_phrase] which is > a reference, so you can replace by a function adding markers around > the text. > > This won't catch error/warning messages. If you also want to > distinguish these, you can redirect the standard formatters. The > toplevel prints replies and error messages on the formatter passed to > [Toploop.loop], which is [Format.std_formatter] by default. So you can > either: > (1) override [Format.std_formatter] callbacks > (2) call [Toploop.loop] with a custom formatter > > You can do (1) with [Format.pp_set_all_formatter_output_functions] and > (2) by setting the startup hook: > > Toploop.toplevel_startup_hook := (fun () -> Toploop.loop my_formatter; > exit 0) > > Warnings are always printed on [Format.err_formatter] so you'll need > to override its callbacks. > > If you can't create a custom toplevel, I guess you can also send the > code to the toplevel at the beginning of the session. Thanks a lot, this was most helpful. This is what I ended up doing. The following, when evaluated, will send all the information from the toplevel to some file, and only output in the toplevel things that are explicitly printed. #+begin_src ocaml let _,_,newline,space = Format.pp_get_all_formatter_output_functions Format.std_formatter ();; let outfile = open_out "/Users/schmitta/tmp/testoutml.txt";; let myout s p n = Printf.fprintf outfile "%s" (String.sub s p n);; let myflush () = flush outfile;; Format.pp_set_all_formatter_output_functions Format.std_formatter myout myflush newline space;; #+end_src Alan