From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA18243; Fri, 12 Jul 2002 09:55:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA18252 for ; Fri, 12 Jul 2002 09:55:49 +0200 (MET DST) Received: from cirse.saclay.cea.fr (cirse.saclay.cea.fr [132.166.192.127]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6C7tnf21433 for ; Fri, 12 Jul 2002 09:55:49 +0200 (MET DST) Received: from argiope.saclay.cea.fr (argiope.saclay.cea.fr [132.166.192.108]) by cirse.saclay.cea.fr (8.12.2/8.12.2/CEAnet-Internet.1.0) with ESMTP id g6C7tncH025312 for ; Fri, 12 Jul 2002 09:55:49 +0200 (MEST) Received: from muguet.saclay.cea.fr (unverified) by argiope.saclay.cea.fr (Content Technologies SMTPRS 4.2.10) with ESMTP id for ; Fri, 12 Jul 2002 09:48:46 +0200 Received: from is002254.saclay.cea.fr (is002254.saclay.cea.fr [132.166.134.67]) by muguet.saclay.cea.fr (8.12.2/8.12.2/CEAnet-Interne.1.0) with ESMTP id g6C7tmlU023897; Fri, 12 Jul 2002 09:55:48 +0200 (MEST) Received: from basile by is002254.saclay.cea.fr with local (Exim 3.35 #1 (Debian)) id 17SvGf-0001pN-00; Fri, 12 Jul 2002 09:55:09 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <15662.35674.992538.745051@is002254.saclay.cea.fr> Date: Fri, 12 Jul 2002 09:55:06 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Functional scanning facilities In-Reply-To: <200207120724.JAA17517@pauillac.inria.fr> References: <86r8i93bti.fsf@laurelin.dementia.org> <200207120724.JAA17517@pauillac.inria.fr> X-Mailer: VM 7.03 under Emacs 21.2.1 From: Basile STARYNKEVITCH Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "Pierre" == Pierre Weis 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