From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 D48327FCCB for ; Thu, 30 Apr 2015 22:26:34 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of omeragacan@gmail.com) identity=pra; client-ip=209.85.212.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="omeragacan@gmail.com"; x-sender="omeragacan@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of omeragacan@gmail.com designates 209.85.212.175 as permitted sender) identity=mailfrom; client-ip=209.85.212.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="omeragacan@gmail.com"; x-sender="omeragacan@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-wi0-f175.google.com) identity=helo; client-ip=209.85.212.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="omeragacan@gmail.com"; x-sender="postmaster@mail-wi0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CxAQCJjkJVlK/UVdFcg19cBYMWxA2GCAKBUAc7EQEBAQEBAQERAQEBAQcLCwkfMIQhAQEEEhEdARsdAQMMBgULDQICJgICIgERAQUBHAYTIod0AQMRDahVPjGLOYFrgnaIfgoZJw1VhEoBAQEBAQEEAQEBAQEXAQUOgROKF4JrgWczB4JogUUFj0aGLYY/gWCSUxIjgQwJgiocgW0iMYJFAQEB X-IPAS-Result: A0CxAQCJjkJVlK/UVdFcg19cBYMWxA2GCAKBUAc7EQEBAQEBAQERAQEBAQcLCwkfMIQhAQEEEhEdARsdAQMMBgULDQICJgICIgERAQUBHAYTIod0AQMRDahVPjGLOYFrgnaIfgoZJw1VhEoBAQEBAQEEAQEBAQEXAQUOgROKF4JrgWczB4JogUUFj0aGLYY/gWCSUxIjgQwJgiocgW0iMYJFAQEB X-IronPort-AV: E=Sophos;i="5.11,678,1422918000"; d="scan'208";a="138385263" Received: from mail-wi0-f175.google.com ([209.85.212.175]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Apr 2015 22:26:34 +0200 Received: by widdi4 with SMTP id di4so33390971wid.0 for ; Thu, 30 Apr 2015 13:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=s1hhFZWE52m4Yfpj9Yg9DCtwT5ZI1qvODiHTO1LwQ8I=; b=cTcLPOZoUY4Yt1fU9XakSxMn6J9vW86AETA94zYdZAE61vnmgTJoGkDj/bYuU5D34j PlmLunBcVTCyJuSwDgOwWvjf1dczf8oRfsEHizYSdNAqRaELqmmGKINY/oHuSICU/SH2 lE9luhBQ0nPaERqLYU0vRObq+UoA5B31CJChr6eHXZxZi/1clbOYiynJp4wCRt6nuRAx M32Yk8g1/uxyMwYw3nwpbSebA5tA1Yha2kLqhS4SDnhRHH3dsVgupe9UDP8OwLbQuROu ylsaTM/WXd+/mWW+fyBQf3W9eyhnx78r6JWpQDoe/gErMggBC+VS8j8iwMStg9xDTzc6 JXfQ== X-Received: by 10.180.14.67 with SMTP id n3mr8437378wic.92.1430425593773; Thu, 30 Apr 2015 13:26:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.187.212 with HTTP; Thu, 30 Apr 2015 13:25:53 -0700 (PDT) In-Reply-To: <5542880D.2060008@mcmaster.ca> References: <5542880D.2060008@mcmaster.ca> From: =?UTF-8?Q?=C3=96mer_Sinan_A=C4=9Facan?= Date: Thu, 30 Apr 2015 16:25:53 -0400 Message-ID: To: Jacques Carette 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 Thanks for the answer. My main problem is not that some generated code are not printable -- rather, it's not clear at all when a code is not printable. Now I have to play arou= nd with code until suddenly it's printable... Certainly not all code is printable even in theory, for example, what happe= ns if my generated code captures a file handle from code generator? Or a heap object that's completely opaque to runtime system.(no type information etc.= ) In those cases it may be possible to directly run the code but it's not possib= le to print it. But IMHO MetaOCaml should have done a better job at reporting those. Or at least at least documenting when it's not possible. I guess I have to play around and see if some of my random changes make it printable. --- =C3=96mer Sinan A=C4=9Facan http://osa1.net 2015-04-30 15:52 GMT-04:00 Jacques Carette : > You will have some difficulties printing complex closures, especially when > they refer to values built in the generator (CSPs) which are not simple > values (strings, integers, etc). > > Sometimes, very simple changes to the generator can allow closures and CS= Ps > to be printable or not -- without very specific examples, I can't help (i= t's > been a few years since I dug into this deeply). > > I have been able to print rather complex, large codes with metaocaml. But > one has to structure the generator rather carefully to ensure this > possibility. > > Jacques > > > On 2015-04-30 14:36 , =C3=96mer Sinan A=C4=9Facan wrote: >> >> Hi all, >> >> I'm working on a MetaOCaml program and I want to save generated programs >> to >> files instead of directly running them within the same program using >> `Runcode.(.!)` or `Runcode.run`. The problem is MetaOCaml never prints >> generated code, it's always failing with `Warning 22: The CSP value is a >> closure or too deep to serialize`. >> >> I can't see anything related in it's web page: >> http://okmij.org/ftp/ML/MetaOCaml.html. What I understand from that page >> is >> once I have a closed code, I should be able to print it no matter what. >> However in my experience even the simplest realistic MetaOCaml program >> fails to >> generate the code because of this error I mentioned above. >> >> (One thing to note here is that my program generates the code on a couple >> of >> inputs, but fails in most of them with this error message.) >> >> In "Many ways to run the code" section it's said that "Since closed code >> is >> essentially OCaml AST, after closing the generated code, the user may >> examine >> and `run' it in many ways. One way of running the code is printing it." >> and >> then it lists some API functions for printing. In my experience none of >> them >> really work, I have closed code which I successfully closed using >> `Runcode.close_code`, but `print_closed_code` is still failing with the >> error, >> and `print_code_as_ast` is printing something that definitely doesn't lo= ok >> like >> an AST for any imaginable programming language.(okay... I might have >> exaggerated a bit, but it's definitely not OCaml AST and it contains some >> references to generator program source, like "Generator.ml[248]" for >> example) >> >> One relevant thing I could find in the documentation is this: "If the co= de >> includes CSP only as literals or external references (and any code can be >> arranged that way), the code can be stored into a file and then passed to >> ocamlopt." If we remove this sentence from the documentation, I don't >> think it >> mentions about any possible failures in code printing. >> >> So now that I've expressed my frustration about this, I guess my main >> question >> is: In what cases does MetaOCaml prints generated code? In what cases it >> doesn't? Note that it fails to generate code even after calling >> `print_closed_code (close_code ...)`, so being closed or not doesn't seem >> very >> relevent here. Is this a bug in MetaOCaml? Are there any workarounds? Any >> ideas >> what am I doing wrong? >> >> Thanks in advance for any answers, >> >> =C3=96mer >> >