Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Alain Frisch <alfie2@ga.mygale.org>, caml-list@inria.fr
Subject: Re: Implémentation de printf
Date: Wed, 19 Aug 1998 17:54:55 +0200	[thread overview]
Message-ID: <19980819175455.59002@pauillac.inria.fr> (raw)
In-Reply-To: <199808060831.KAA01652@wanadoo.fr>; from Alain Frisch on Thu, Aug 06, 1998 at 10:32:45AM +0000

> je cherche à créer une fonction du genre :
> let affiche format arg = mon_affichage (sprintf format arg);;
> mais qui accepte des formats avec plusieurs paramètres. Est-ce
> possible (j'utilise Caml Light 0.7).

Non, ce n'est pas possible.  Étant donné la manière dont les fonctions
*printf consomment leurs arguments, on peut définir une fonction qui
fait quelque chose avant d'appeler printf:

    let affiche format = print_string "**mon prefixe**"; printf format

mais il n'est pas possible de reprendre la main après que printf a
consommé ses arguments.

> D'autre part, en consultant le code source de printf (version 0.6),
> il me vient quelques questions : que sont les fonctions magic, 
> is_block, repr, obj_tag ?

Des primitives de très bas niveau permettant d'accéder directement aux
représentations des structures de données Caml et de contourner le
typage statique strict.  Les utiliser nécessite une compréhension en
profondeur du runtime et du compilateur Caml.  Je ne saurais trop vous
dissuader de vous en servir!

> Est-il possible de créer soi même une fonction du style printf
> (ie:  nombre et type d'arguments variable suivant la valeur d'un 
> paramètre) ?

En restant dans la partie "bien typée" du langage, c'est difficile.
Cependant, vous pouvez regarder le printf d'Olivier Danvy
("Functional Unparsing", http://www.brics.dk/RS/98/Ref/BRICS-RS-98-Ref/BRICS-RS-98-Ref.html#BRICS-RS-98-12).

- Xavier Leroy





      reply	other threads:[~1998-08-19 23:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-06 10:32 Alain Frisch
1998-08-19 15:54 ` Xavier Leroy [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=19980819175455.59002@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=alfie2@ga.mygale.org \
    --cc=caml-list@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