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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id C3AD97ED34 for ; Wed, 11 Jul 2012 04:42:40 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of bobzhang1988@gmail.com) identity=pra; client-ip=209.85.216.47; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of bobzhang1988@gmail.com designates 209.85.216.47 as permitted sender) identity=mailfrom; client-ip=209.85.216.47; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qa0-f47.google.com) identity=helo; client-ip=209.85.216.47; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="postmaster@mail-qa0-f47.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiMCAFTn/E/RVdgvk2dsb2JhbABFDrdpCCIBAQEBCQkLCRQEI4IgAQEBBAEBAQ8CJAgBGxILAQMMBgULDQklDwISEQEFARwGDQEHAQEeh1sBAwyeVgkDjCOCcYUQChknDVeIcQEFDJEiA5U2jig+g0VV X-IronPort-AV: E=Sophos;i="4.77,564,1336341600"; d="scan'208";a="150260002" Received: from mail-qa0-f47.google.com ([209.85.216.47]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 11 Jul 2012 04:42:39 +0200 Received: by qabg1 with SMTP id g1so2989568qab.6 for ; Tue, 10 Jul 2012 19:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:newsgroups:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=OD9wxEDGFifxtVDgtEclygbcu/Cs+1KgPfJhn/5VGMs=; b=UJIP79L3wNpD9aNvOuQjkipI346YMyx/4cfvEus8wC8X4tlbz8+1XJl9O7GrVF42Ed Cp/p6qWKnLw/nSV36Dd4zRE4UkV2A8OViIOLdRJJV+v/Z2y09U9FmR1pP9s8rsSvlG9e 37z6xkXs/PtZLWPQJypHXbOv4Dc8WRtzzeTWyixQPZ5t8FsbUtC8McKeQj3NJlENR7mv ctwXxOoVdi76kc1HHJUYTketbkXdbCdfE0KfevYtzryELzNa9fY+NL8kDzkV9ou+3wI1 1/TcnA72V7Rl0vV9ac+8uum5YxTwzf7hepmAXo7uRHZzv45tY9Uy9Po0oH3hY6oacZk+ PHYg== Received: by 10.224.72.210 with SMTP id n18mr83960923qaj.10.1341974558527; Tue, 10 Jul 2012 19:42:38 -0700 (PDT) Received: from Hongbos-MacBook-Air.local ([66.250.143.158]) by mx.google.com with ESMTPS id fx5sm1525222qab.14.2012.07.10.19.42.37 (version=SSLv3 cipher=OTHER); Tue, 10 Jul 2012 19:42:37 -0700 (PDT) Message-ID: <4FFCE81A.80700@gmail.com> Date: Tue, 10 Jul 2012 22:42:34 -0400 From: Hongbo Zhang User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 Newsgroups: gmane.comp.lang.caml.inria To: Jean-Baptiste Jeannin CC: "caml-list@inria.fr" References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Caml-list] Re: Returning an element computed with Toploop On 7/10/12 11:08 AM, Jean-Baptiste Jeannin wrote: > Hello all, > Hi, > Thanks to Jonathan Kimmitt on this mailing list, I learned about the existence of the Toploop module, that allows to execute OCaml code from a string. For example, one can do: > > # Toploop.execute_phrase true Format.err_formatter > ((!Toploop.parse_toplevel_phrase) (Lexing.from_string "355./.113.;;"));; > - : float = 3.14159292035398252 > - : bool = true > Use Tooploop.getvalue. > However I could not find any official documentation of the module on the internet. In particular, the example above only prints out what was computed and returns a boolean (true or false), depending on how the computation terminated. I would like to compute an element and get the element back to be able to use it later in the computation. Is that possible and how could I do it? > The codebase for toplevel/ is pretty small, IMHO, reading the source is best way to understand how toploop works. There's another non-trivial example in camlp4/Camlp4Top which shows you how to customize toplevel. If you understand how it works, feel free to use it, it's pretty safe :-) > Thanks a lot, > Jean-Baptiste >