From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: Text_IO, was: Re: Something I don't understand Date: Mon, 17 Feb 2014 18:13:40 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <4a3e55f6-9f54-4084-9f37-96efd4b0d349@googlegroups.com> <0b358700-871b-4603-addd-65e07c7d59e5@googlegroups.com> Injection-Date: Mon, 17 Feb 2014 18:13:40 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="e458ff8b81bc0c159989eb0e36c6e372"; logging-data="24872"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//n/qqmqxcH3viut9QepM/GMF/JKYhNKY=" User-Agent: slrn/0.9.8.1 (VMS/Multinet) Cancel-Lock: sha1:GgowSsildDIvbbKLTjnxJNMUrSI= Xref: number.nntp.dca.giganews.com comp.lang.ada:184946 Date: 2014-02-17T18:13:40+00:00 List-Id: On 2014-02-17, Niklas Holsti wrote: > On 14-02-17 14:52 , Simon Clubley wrote: >> On 2014-02-16, Robert A Duff wrote: > [snip] >>> A simplified and type-safe version of C's printf style >>> (template-based) formatting would be more readable than >>> concatenating a bunch of strings together to print messages, >>> and MUCH better than using a series of Put calls to print >>> a single message. >>> >> >> _Totally_ agree with this. > > I disagree, but then I don't understand how Robert would make C's > template idea type-safe -- might Robert expand on his ideas? > Oh, I can see a way in which it can be made fully type safe. Assume that support for internal to external conversions is implemented within the type itself as Robert suggests. Furthermore, assume, as I suggested, that you need to pass a format parameter to the type in order for the value to be formatted as required. The Ada version of printf would iterate over the combined format string and pass the fragment of it intended for the formatting of the current variable to the variable type's Internal_To_External support routine. If the passed format fragment was compatible with the data type, the Internal_To_External routine would process the format and return the formatted string back to the Ada version of printf so it can be added into the output buffer. If, OTOH, the format fragment was incompatible with the data type, the Internal_To_External support routine within the type would raise a exception. And voila, C printf templates in a fully Ada type safe manner. Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world