caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile STARYNKEVITCH <basile.starynkevitch@cea.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Functional scanning facilities
Date: Fri, 12 Jul 2002 09:55:06 +0200	[thread overview]
Message-ID: <15662.35674.992538.745051@is002254.saclay.cea.fr> (raw)
In-Reply-To: <200207120724.JAA17517@pauillac.inria.fr>

>>>>> "Pierre" == Pierre Weis <pierre.weis@inria.fr> writes:

    Pierre> Here, we want to design and implement a practical,
    Pierre> compact, simple to understand, and easy way to print and
    Pierre> scan in the context of a functional language with
    Pierre> full-fledged imperative features [...]

    Pierre> In this favourable situation, I'm afraid no combinatorial
    Pierre> approach can compete with the readability and compactness
    Pierre> of C-style formats. [...]

I'm not expert enough about combinators, but I have a tiny suggestion
regarding formats (I implemented this suggestion in C++ a few years
ago).

I think that internationalization or localization is very important
today and it wasn't even thinkable at the time -20 [C printf] or 40
years [Fortran Format] ago- formats have been invented.

The idea is that the format string is a true string (typically
localized thru a gettext(3) or equivalent stuff) containing "format
variables". Then the arguments are "bindings" of these "format
variables" to values. Of course what I call "format variables" and
"bindings" is unrelated to the variables and bindings of Ocaml (which
have sense at compile time only; at runtime we only have values and
closures).

So instead of doing

    printf "a=%d x=%g" a x

or perhaps (this certainly does not work today)

    printf (gettext "a=%$1d x=%$2g") a x

my suggestion would be something like

    printb "a=$A x=$B" (PrintIntBind ('A',a)) (PrintRealBind ('B',x))

where we have a type like

printbinding_t = PrintIntBind of char * int | PrintRealBind of char * float 
               | ....

Now of course the code in my example is clumsy. What is needed is just
some syntactic device (e.g. a suitable camlp4 macro, or even a builtin
device in Ocaml like the lazy keyword) to shorten e.g. the
(PrintIntBind ('A',a)) syntax into something shorter, e.g. such as

    printb "a=$A x=$B" @i:A=a @f:B=b

or even, having localization in mind, something like

   lprintb "a=$A x=$B" @i:A=a @f:B=b

which would be a syntax for 

   printb (gettext "a=$A x=$B") (PrintIntBind ('A',a)) (PrintRealBind ('B',x))

I think that formatted input and output is in practice important
enough to be assisted thru specific syntax extension.


Regarding the current ('a,'b,'c) format type, I am lacking of
documentation on the type variables 'a 'b and 'c. I also think that it
is pityful that the "%a" and "%t" functional printers have a type
which depends if they occur inside a Printf.printf Printf.bprintf or
Printf.sprintf function


I am very glad that the forthcoming Ocaml release has a scanf (and a
kprintf) facilities. Both are very invaluable. Thanks again to the
Ocaml team for the great work!

N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

---------------------------------------------------------------------
Basile STARYNKEVITCH   ----  Commissariat à l Energie Atomique * France
DRT/LIST/DTSI/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX 
phone:+33 1,6908.6055; fax: 1,6908.8395 home: 1,4665.4553; mobile: 6,8501.2359
work email: Basile point Starynkevitch at cea point fr 
home email: Basile at Starynkevitch point net

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-07-12  7:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-12  1:36 Alessandro Baretta
2002-07-12  2:43 ` John Prevost
2002-07-12  7:24   ` Pierre Weis
2002-07-12  7:55     ` Basile STARYNKEVITCH [this message]
2002-07-12  7:58     ` John Prevost
2002-07-12  8:25     ` Stefano Zacchiroli
2002-07-12 11:16       ` Pierre Weis

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=15662.35674.992538.745051@is002254.saclay.cea.fr \
    --to=basile.starynkevitch@cea.fr \
    --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;
as well as URLs for NNTP newsgroup(s).