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 36C7A7F6CB for ; Tue, 10 Feb 2015 09:34:46 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jpathy@fssrv.net) identity=pra; client-ip=74.125.82.47; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="jpathy@fssrv.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of jpathy@fssrv.net designates 74.125.82.47 as permitted sender) identity=mailfrom; client-ip=74.125.82.47; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="jpathy@fssrv.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wg0-f47.google.com) identity=helo; client-ip=74.125.82.47; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="postmaster@mail-wg0-f47.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B9AgDWwdlUmy9SfUpcg1haBIJ+wAcMhW8CgRcHQwEBAQEBARABAQEBAQYLCwkULoQNAQEEAQIPEQQZAQE3AQ8LCwMKAgImAgIiEgEFARwGExoIiAsNqkg+MYo+cIRiAQWSGQEBAQEBBQEBAQEBFwYKgReOVgeCaIFCiiyIRIVcgU6PWBIjgRWEMR0xAQGCQAEBAQ X-IPAS-Result: A0B9AgDWwdlUmy9SfUpcg1haBIJ+wAcMhW8CgRcHQwEBAQEBARABAQEBAQYLCwkULoQNAQEEAQIPEQQZAQE3AQ8LCwMKAgImAgIiEgEFARwGExoIiAsNqkg+MYo+cIRiAQWSGQEBAQEBBQEBAQEBFwYKgReOVgeCaIFCiiyIRIVcgU6PWBIjgRWEMR0xAQGCQAEBAQ X-IronPort-AV: E=Sophos;i="5.09,549,1418079600"; d="scan'208";a="99502099" Received: from mail-wg0-f47.google.com ([74.125.82.47]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 10 Feb 2015 09:34:45 +0100 Received: by mail-wg0-f47.google.com with SMTP id n12so31852118wgh.6 for ; Tue, 10 Feb 2015 00:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fssrv.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eg3AXoiCJ0LTdJzp/qiuq2+d/Q6IOJmFFIc/XSzlKtg=; b=Xt/ZIYVOvRrjWfONWZHFgZ2fPYvj2uIyuq/qnB9kGyn6VtAMJ0run7FcuuRUofagHy OSO5UtdvL4YtBikeoyowlraAd8lwxHOf2IZlDv2vcm5Dop08mwt1qFhV2IijFK1Yn0/X t2JC3IAu+B26GATd/p+GheNx8IZY9rvA8Bon8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=eg3AXoiCJ0LTdJzp/qiuq2+d/Q6IOJmFFIc/XSzlKtg=; b=GtJLd54lkEmFu9d5L7A4azoUCRyQGWGbkbV73CrubrBexfaHCZTqSzPFaZpR/tLTxA SKR1frxXO1y8cXRpCKGfdnknS06aZbVQksRzRPSG4uSxbXer7aJ2xHF1aYR/VoHbiyoa Ijo4TX6ORdci+t0XOqPllQhHKEfxUP+HDhuzUByk9yXDBmO4YS8daa0XMnm9j6LRQ0GV sATUWqjf4MuEiIeOmKYfOR8m9bWuCYBzjXF9ZmO0MCiMMZaKBAmsPuhJHv/S6J8uiChx AYWek53sHFprtmqq8mvQ1f8mh9jkB7jz3Vgndd4kzyrxi8SAX8JnV1WG9aUB2sF7QVrN NFqQ== X-Gm-Message-State: ALoCoQl+tUSgBEkmA5p+zwhY9PFUd9LMSCeRMneQoG08ymWFQODnCB2hhWSCg5YxHmJutIfSzI5i MIME-Version: 1.0 X-Received: by 10.194.110.137 with SMTP id ia9mr50370308wjb.153.1423557285306; Tue, 10 Feb 2015 00:34:45 -0800 (PST) Received: by 10.27.226.67 with HTTP; Tue, 10 Feb 2015 00:34:45 -0800 (PST) In-Reply-To: References: Date: Tue, 10 Feb 2015 00:34:45 -0800 Message-ID: From: Jiten Pathy To: David Allsopp Cc: "caml-list@inria.fr" Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] format strings Thanks, that helps. I can't think of any complicated manipulation i would need, for now. On Tue, Feb 10, 2015 at 12:25 AM, David Allsopp wrote: > Jiten Pathy wrote: >> Ok, If i am not supposed to use make_printf, then what is the recommended >> way of writing the following? >> >> This adds a new line to given format string. In particular how do i >> manipulate the format strings passed to me? > > There wasn't a vast amount of type-safe manipulation possible with format strings in the old implementation, though given the newer representation, perhaps something may come in the future. > >> open CamlinternalFormat;; >> let f (Format (fmt, _)) = >> make_printf (fun o acc -> output_acc o (Acc_char_literal (acc, '\n')); >> ignore o) stdout End_of_acc fmt ;; val f : ('a, out_channel, unit, unit, >> unit, unit) format6 -> 'a = >> >> utop # f "%s %d" "# " 3;; >> # 3 >> - : unit = () > > However, for this "simple" manipulation there are two ways which don't touch the internals: > > let f fmt = Printf.ksprintf (Printf.printf "%s\n") fmt > > [that's my preference - to me it's clearer that you're wrapping the formatted output. I'd often do this to add %! as well - i.e. "%s\n%!"] > > let f fmt = Printf.printf (fmt ^^ "\n") > > [See http://caml.inria.fr/pub/docs/manual-ocaml-4.02/libref/Pervasives.html#6_Operationsonformatstrings] > > > David