From: aek@vib.usr.pu.ru (Alexander Kopilovitch)
Subject: Re: Literals for Private Types
Date: 9 Dec 2003 19:25:01 -0800
Date: 2003-12-09T19:25:01-08:00 [thread overview]
Message-ID: <e2e5731a.0312091925.5d58c44b@posting.google.com> (raw)
In-Reply-To: mailman.58.1071007000.31149.comp.lang.ada@ada-france.org
It appears that my previous posting on this subject had a slip inside the code
line proposed for inclusion in Ada.Strings.Unbounded (which teaches that even
a brief and informal text should be reviewed by another person if it contains
some code -;) in paragraph 4 - there must be
for Unbounded_String'Literal_Conversion use To_Unbounded_String;
So, here is the corrected text:
-----
1. Both String and numeric literals become possible for any user-defined type,
including private types.
2. Two new attributes is all that needed for that: Literal_Conversion attribute,
defines a family of conversion functions for a type, while With_Literals
attribute, being attached to a subprogram's formal parameter permits implicit
conversion of literal actual argument for the parameter.
The With_Literal attribute provides necessary control over ambiguity, which
always was a major obstacle for the issue of literals for user-defined types.
Appropriate parameters of all predefined operations of the type are considered
as equipped with the With_Literals attribute, so implicit conversions of
literal actual arguments is always permitted for them.
3. The Literal_Conversion attribute should be defined within the type's specs
by usual method:
type T is ...;
for T'Literal_Conversion use F;
(function F must take single String or numeric argument and return T).
The With_Literals attribute need not be defined at all - actually it acts more
like a pragma, but an attribute form it is simply more natural and convenient
for the case:
procedure P (Arg : in T'With_Literals);
4. With that proposal, the String literals for Unbounded_String type can be
introduced by adding exactly one statement to Ada.Strings.Unbounded specs:
for Unbounded_String'Literal_Conversion use To_Unbounded_String;
The direct effect of this addition will be an opportunity to assign String
literals to Unbounded_Strings without explicit conversion.
The subprograms defined in Ada.Strings.Unbounded package will not be affected
because they have no With_Literals attribute attached to their parameters.
Then, if we wish to allow implicit conversion from string literals for our
user-defined function Compare, we must use With_Literal attributes for its
parameters:
function Compare (Source : in Unbounded_String'With_Literals;
Target : in Unbounded_String'With_Literals)
return Boolean;
-----
Alexander Kopilovitch aek@vib.usr.pu.ru
Saint-Petersburg
Russia
next prev parent reply other threads:[~2003-12-10 3:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-09 21:06 Literals for Private Types Alexandre E. Kopilovitch
2003-12-10 3:25 ` Alexander Kopilovitch [this message]
2003-12-10 7:57 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox