From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.7 required=3.0 tests=BAYES_00,NICE_REPLY_A, REPLYTO_WITHOUT_TO_CC,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Parameterised 'Image Attributes Date: Sun, 20 Aug 2023 09:53:11 +0200 Organization: A noiseless patient Spider Message-ID: References: Reply-To: nonlegitur@notmyhomepage.de MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 20 Aug 2023 07:53:12 -0000 (UTC) Injection-Info: dont-email.me; posting-host="3b9e818ded4c7241af4a58064e181b99"; logging-data="1362280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7hZJy4VJIpoBTjWX15FQOtuiOGX4BPZs=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Cancel-Lock: sha1:EpXxkyF2EnVJfzimXWFWMSxUQ0U= Content-Language: en-US In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65544 List-Id: On 19.08.23 17:27, Jeffrey R.Carter wrote: > On 2023-08-19 11:14, J-P. Rosen wrote: >> On 18/08/2023 08:18, Rod Kay wrote: >>> >>>     Would it be possible/desirable to allow the 'Image attribute to have formatting parameters ? Something along the lines of ... >> >> The intent of the 'Image attribute is to have a quick representation, mainly for debugging purposes. If you want nice formatted output, use the Put procedure on String from Text_IO > (...) > The obvious solution is to have a library containing appropriate functions, which can be built around the Put procedures while still being functions. Such functions would need to be generic, unlike attribute functions which are automatically available for all types. > > The conflict between this common need and the minimal functionality provided by 'Image results in such requests. It seems desirable for the language to provide such functions, and extending the 'Image functions seems like a reasonable way for it to do so, regardless of the original intentions for the attribute. So, also - See how other languages address formats (good bits, bad bits). - Consider use cases. - I/O is the program(mer)'s raison d'être. Can we easily Put something into a stream without the help of a suitable library? Could there be a language defined type F whose purpose is to support the description of formats? Objects of type F would "configure" what 'Image does when computing a representation of a date, a number, ... My_Length'Image (Arg => diameter, Format => ___); Some use cases: - I18n of number formats (cf ARM F.3), CHF 1'234'000.– - Handle ubiquitous ISO formats of date-time (as mentioned below; also cf. ARM 9.6.1) - reporting, - integrate own output with output of other system components (a site-wide monitoring system searches outputs, say) - fill in templates when these do not support formatting - 'Input an object of type F at run-time, so that program's use of 'Image can be changed according to customer's local expectations. - support the formalized exchange of "numerical" data in heterogeneous systems, using text streams. These use cases are about the O of I/O. By symmetry, it would be nice to have implementations of Ada that support the I part of this kind of I/O, I think, with work to be split between implementers and programmers. My_Length'Value (Arg => diameter, Format => ___); Or perhaps multimethods that take a stream and a format when they need to write a value? > One library with such functions is the PragmAda Reusable Components (https://github.com/jrcarter/PragmARC). The package PragmARC.Images (https://github.com/jrcarter/PragmARC/blob/Ada-12/pragmarc-images.ads) provides such functions for integer and floating-point types. Function PragmARC.Images.Image is an instantiation for Standard.Integer. > > PragmARC.Date_Handler (https://github.com/jrcarter/PragmARC/blob/Ada-12/pragmarc-date_handler.ads) provides image functions for dates and times; although the language now provides a function for a date-time image, Date_Handler continues to be useful as it provides for customized formats rather than the single format provided by Ada.Calendar.Formatting. Many users also find the semantics of the latter's time-zone parameter to be confusing. > > (ISO/IEC 8652:2023 provides a date-time image function the returns the image for the local time zone, but as there are no compilers* for this version of the language, I don't consider that relevant.