From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
Subject: Re: Parameterised 'Image Attributes
Date: Sat, 19 Aug 2023 17:27:25 +0200 [thread overview]
Message-ID: <ubqn0t$o3lq$1@dont-email.me> (raw)
In-Reply-To: <ubq15l$oa8i$1@dont-email.me>
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
next prev parent reply other threads:[~2023-08-19 15:27 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-18 7:18 Parameterised 'Image Attributes Rod Kay
2023-08-18 8:25 ` Luke A. Guest
2023-08-19 9:14 ` J-P. Rosen
2023-08-19 10:03 ` Dmitry A. Kazakov
2023-08-19 11:45 ` Luke A. Guest
2023-08-19 11:56 ` J-P. Rosen
2023-08-19 13:01 ` Dmitry A. Kazakov
2023-08-19 15:27 ` Jeffrey R.Carter [this message]
2023-08-20 7:53 ` G.B.
2023-08-20 9:27 ` Dmitry A. Kazakov
2023-08-21 23:11 ` Randy Brukardt
2023-08-21 23:37 ` Randy Brukardt
2023-08-22 7:38 ` Dmitry A. Kazakov
2023-08-19 16:49 ` moi
2023-08-20 7:25 ` Randy Brukardt
2023-08-20 9:43 ` Dmitry A. Kazakov
2023-08-21 23:34 ` Randy Brukardt
2023-08-22 8:13 ` Dmitry A. Kazakov
2023-08-23 10:20 ` Stephen Davies
2023-08-23 16:16 ` Dmitry A. Kazakov
2023-08-24 19:59 ` Stephen Davies
2023-08-25 7:26 ` Dmitry A. Kazakov
2023-08-25 9:04 ` Stephen Davies
2023-08-25 13:02 ` Dmitry A. Kazakov
2023-08-28 9:18 ` Stephen Davies
2023-08-28 10:58 ` Dmitry A. Kazakov
2023-08-28 15:42 ` Stephen Davies
2023-08-28 16:09 ` Dmitry A. Kazakov
2023-08-28 17:33 ` G.B.
2023-08-28 19:08 ` Dmitry A. Kazakov
2023-08-28 17:58 ` Niklas Holsti
2023-08-28 19:08 ` Dmitry A. Kazakov
2023-09-07 1:04 ` Randy Brukardt
2023-09-07 9:01 ` Dmitry A. Kazakov
2023-08-18 18:53 ` Keith Thompson
2023-09-23 10:00 ` Rod Kay
2023-09-26 5:47 ` Vadim Godunko
2023-09-26 10:15 ` Rod Kay
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox