Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Functional scanning facilities
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Basile STARYNKEVITCH <basile.starynkevitch@c...>
Subject: Re: [Caml-list] Functional scanning facilities
>>>>> "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