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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 4F9027FCCB for ; Thu, 30 Apr 2015 23:35:56 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.220.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of yallop@gmail.com designates 209.85.220.178 as permitted sender) identity=mailfrom; client-ip=209.85.220.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qk0-f178.google.com) identity=helo; client-ip=209.85.220.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-qk0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CgAQAVn0JVm7LcVdFcg19QDAWDFsQKhgwCgVAHPBABAQEBAQEBEQEBAQEBBgsLCSEuhCEBAQQSEQQZARsYBQEDAQsGBQsNAgImAgIhAQERAQUBHAYTIod0AQMRqEU+MYs5gWuCdokGChknDVWESgEBAQEBBQEBAQEBARYBBQ6BE4oXgk2CBTMHgmiBRQWVc4RrgVSBYI1ChRESI4EMCYIIghA9MYJFAQEB X-IPAS-Result: A0CgAQAVn0JVm7LcVdFcg19QDAWDFsQKhgwCgVAHPBABAQEBAQEBEQEBAQEBBgsLCSEuhCEBAQQSEQQZARsYBQEDAQsGBQsNAgImAgIhAQERAQUBHAYTIod0AQMRqEU+MYs5gWuCdokGChknDVWESgEBAQEBBQEBAQEBARYBBQ6BE4oXgk2CBTMHgmiBRQWVc4RrgVSBYI1ChRESI4EMCYIIghA9MYJFAQEB X-IronPort-AV: E=Sophos;i="5.11,679,1422918000"; d="scan'208";a="138391253" Received: from mail-qk0-f178.google.com ([209.85.220.178]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Apr 2015 23:35:55 +0200 Received: by qkx62 with SMTP id 62so41609133qkx.0 for ; Thu, 30 Apr 2015 14:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Fsgfov7Gt4k3ul0GOKFFCjszfToB64wZhRZBUFse0Pg=; b=nt60hXS1Jg12AIxh6uHn2E3rqo7nyXE32RkQwaEWXqlzH9F8Qr73jQ7vDmAkr2vkLT sTS4VePBFhoiw64cXM4bNgYrT2WVETNgLxEWStrlv6KmZGG+F2BiRaTKYiMbBMqOTZSR 5IyL9HrMwejL9voYzPAtzLaS2g0dUXWI8CTTAIUwT4qayAfaQLIQXP8pHwXUEbV2PFC3 hmvrjfHgiyU2v5RAq4SSQ3qDR0mQ0FogyuuMeYWTik4xp6O9udUWr2o13eAe0PhXXvfF MTp/NaHRKY0QqK7kfCEU19OHoR99bFIv/UU2g+Ey33+/RPJtQ+Y6p09bWPf/HS04u1Mq Q+XA== MIME-Version: 1.0 X-Received: by 10.229.96.199 with SMTP id i7mr497608qcn.6.1430429754490; Thu, 30 Apr 2015 14:35:54 -0700 (PDT) Received: by 10.229.40.7 with HTTP; Thu, 30 Apr 2015 14:35:54 -0700 (PDT) In-Reply-To: References: <5542880D.2060008@mcmaster.ca> Date: Thu, 30 Apr 2015 22:35:54 +0100 Message-ID: From: Jeremy Yallop To: =?UTF-8?Q?=C3=96mer_Sinan_A=C4=9Facan?= Cc: OCaml Mailing List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Problems with printing MetaOCaml generated code On 30 April 2015 at 21:57, =C3=96mer Sinan A=C4=9Facan wrote: > Let's talk on an example: > > -- contents of TestData.ml > type foo =3D Foo of int > > -- contents of main > open TestData > > let global_ref : int ref =3D ref 0 > > let gen_inc =3D > .< let _ =3D global_ref :=3D !global_ref + 1 in () >. You can improve the output here (and everywhere else that you use global_ref in a quotation) by putting the global reference in a separate file, so that MetaOCaml can persist it as a path: let gen_inc =3D .< let _ =3D Globals.global_ref :=3D !Globals.global_ref + 1 in () >. > let gen_write i =3D > .< match i with > | Foo i -> global_ref :=3D i > >. In this case the problem is that 'i' is a local variable bound to a current-stage value. It's better to make it a future-stage (code) expression, and splice that in: let gen_write i =3D .< match .~i with | Foo i -> global_ref :=3D i >. You'll also need to change the call: gen_write .. > let gen_cls_wrt cls =3D > .< global_ref :=3D cls () >. This time there are two problems. First, cls is local, as with 'i' above. Second, 'cls' is a closure (function), so it doesn't have a printed representation. You can address the problem by making cls either a code value or a top-level path, e.g. .< Globals.global_ref :=3D Globals.cls () >. or .< Globals.global_ref :=3D .~cls () >. With these changes the program runs without warnings or errors and generates compilable code without CSP comments. > * I don't know if this is MetaOCaml related, but output of this program is > interleaved. Instead of printing a line than code it prints two lines a= nd > then two code etc. How is this possible?? The interleaving is probably due to internal buffering in the format librar= y. Jeremy.