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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,371fb4e2d57c3f18 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-09 19:25:01 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: aek@vib.usr.pu.ru (Alexander Kopilovitch) Newsgroups: comp.lang.ada Subject: Re: Literals for Private Types Date: 9 Dec 2003 19:25:01 -0800 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 213.33.245.27 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1071026701 801 127.0.0.1 (10 Dec 2003 03:25:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 10 Dec 2003 03:25:01 +0000 (UTC) Xref: archiver1.google.com comp.lang.ada:3295 Date: 2003-12-09T19:25:01-08:00 List-Id: 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