caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Remi Vanicat <remi.vanicat@gmail.com>
To: caml-list@yquem.inria.fr
Subject: [Caml-list] printf format strings
Date: Thu, 1 Dec 2005 17:26:31 +0100	[thread overview]
Message-ID: <6b8a91420512010826t540e0308v@mail.gmail.com> (raw)
In-Reply-To: <6b8a91420512010825k23d78780u@mail.gmail.com>

005/12/1, Hendrik Tews <tews@tcs.inf.tu-dresden.de>:
> Jonathan Roewen <jonathan.roewen@gmail.com> writes:
>
>    { fmt %}: convert a format string argument. The argument must have the
>    same type as the internal format string fmt.
>
>    And how to use it? I get Bad format `%{' in the toplevel.
>
> My toplevel accepts it, but does nothing on it:
>
>     # Printf.printf "%{%d%s%}" "kkkk\n" ;;
>     This expression has type
>       (int -> string -> 'a, 'b, 'c, int -> string -> 'a) format4
>     but is here used with type (int -> string -> 'a, 'b, 'c, 'a) format4
>
> This is expected, because kkkk has the wrong type.
>
>     # Printf.printf "%{%d%s%}" "kk%dkk%s\n" ;;
>     - : unit = <unknown constructor>
>
> This should print something I guess. The "unknown constructor"
> looks very suspicious. Maybe the %{ format is meant to generate
> random strings???

Well, I've guessed a bug in the type system, and it seem I'm correct:

let t = Obj.repr (Printf.printf "%{%d%s%}" "kk%dkk%s\n");;
# Obj.is_block t;;
- : bool = true
# Obj.is_block (Obj.repr ());;
- : bool = false
# Obj.tag t;;
- : int = 247
# Obj.closure_tag;;
- : int = 247

So this is a closure, so a function that should have a functional type.


I've tried to play with the devil, and here my result :
# (Obj.magic( Printf.printf "%{%d%s%}" "kk%dkk%s\n") 5 "rae" () : unit );;
%i%s- : unit = ()

Very strange indeed.

Well, this should be reported in the bug tracking system.


      parent reply	other threads:[~2005-12-01 16:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-30 23:31 Jonathan Roewen
2005-12-01 10:18 ` Hendrik Tews
     [not found]   ` <6b8a91420512010825k23d78780u@mail.gmail.com>
2005-12-01 16:26     ` Remi Vanicat [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b8a91420512010826t540e0308v@mail.gmail.com \
    --to=remi.vanicat@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).