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=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: Parameterised 'Image Attributes Date: Sat, 19 Aug 2023 17:27:25 +0200 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 19 Aug 2023 15:27:26 -0000 (UTC) Injection-Info: dont-email.me; posting-host="cbd554b853755d2a6e60e861e37e3278"; logging-data="790202"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Rn5KgWoa5ihaB8z/QBRnoh6o7GNRbkGM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cancel-Lock: sha1:TPTHzS3/EDofntys+c/44tvTZ9U= In-Reply-To: Content-Language: en-US Xref: news.eternal-september.org comp.lang.ada:65541 List-Id: 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. There is a common problem across many types and problem domains of having a function that returns a string of an appropriate length representing a value of the type with desired formatting. Common examples include numeric values, dates, and times. The resulting string is usually combined with other information into a message that may be stored in memory for a while, though it is rare for it not to be output eventually. As an example, the message may be put on a protected queue for later output by a logging task. Ada 83 tended not to include anything that the developer could implement; there was no math library or image functions for dates or times. The 'Image attribute was provided, but is unsuited for most such uses. The use of the Text_IO generic sub-pkg Put procedures that output to strings is not convenient because they are procedures, not functions. Later versions of Ada included more support for such needs, but not for numeric values. 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. 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. (*A compiler for a version of the language implements the entire core language of that version of the ARM.) -- Jeff Carter "The men get one hot meal a day: a bowl of steam." Take the Money and Run 145