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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,371fb4e2d57c3f18,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-09 13:58:38 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!skynet.be!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "Alexandre E. Kopilovitch" Newsgroups: comp.lang.ada Subject: Literals for Private Types Date: Wed, 10 Dec 2003 00:06:01 +0300 (MSK) Organization: h w c employees, b f Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1071007001 23256 80.67.180.195 (9 Dec 2003 21:56:41 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 9 Dec 2003 21:56:41 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: X-Mailer: Mail/@ [v2.44 MSDOS] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.3 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:3294 Date: 2003-12-10T00:06:01+03:00 Near 3 weeks ago I sent to Ada-Comment mailing list my proposal for literals for private types. As no reaction followed there, I concluded that the proposal sank in silence. Therefore I decided to post a brief and informal exposition of that proposal here in comp.land.ada (I suppose that those people who might be interested in full and more formal version are subscribed to Ada-Comment and therefore already saw it). Here it is: ----- 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 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