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-Thread: 103376,5e54ec0ce937978 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newspeer.monmouth.com!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: String literals and wide_string literals - how? Date: Fri, 20 Apr 2007 16:02:55 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1177063665.093083.241580@e65g2000hsc.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1177099375 18595 192.74.137.71 (20 Apr 2007 20:02:55 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 20 Apr 2007 20:02:55 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:HiRyq5dJq2bg8Vec7y0MBnso/EI= Xref: g2news1.google.com comp.lang.ada:15171 Date: 2007-04-20T16:02:55-04:00 List-Id: "Randy Brukardt" writes: > "Robert A Duff" wrote in message > news:wccbqhjw0we.fsf@shell01.TheWorld.com... > ... >> String literals are not necessarily of type String; they can be of any >> "string type". A string type is any one-dimensional array of some >> character type. You can even do weird things like this: >> >> type Bit is ('0', '1'); > > That's not that weird. OK, it's not weird. It's quite elegant, in fact, from at least one point of view -- a character type is "just" an enumeration of the character literals. But I'll bet it _seems_ weird to anyone who doesn't know Ada well. Are there any other languages that have this sort of thing? Many folks presented with the above will assume type Bit above is a subtype of Character, or derived from it. That's why I mentioned that Bit'Size = 1, so the OP would understand that '0' here is not Ascii (or Latin-1, or whatever) '0'. And please don't ask me to actually enumerate all the Wide_Wide_Character literals! To me, it's weird that in almost all languages, the form of a literal determines its type. It seems so much more natural that context should do so. >... My favorite example of this came from an early Ada 83 > book: > > type Roman_Digit is ('I', 'V', 'X', 'L', 'C', 'D', 'M'); > type Roman_Numeral is array (Positive range <>) of Roman_Digit; > Five : constant Roman_Numeral := "V"; > Sixteen : constant Roman_Numeral := "XVI"; > My_Age : constant Roman_Numeral := "XLVIII"; > Claw_Generic_Price : constant Roman_Numeral := "CDXCV"; > Claw_Support_Price : constant Roman_Numeral := "CCC"; > > Now throw in some operator overloading: > > function "+" (Left, Right : Roman_Numeral) return Roman_Numeral; > > and you can work solely in Roman_Numerals. > > Total : constant Roman_Numeral := Claw_Generic_Price + > Claw_Support_Price; > > Cool, even if rather useless. (I don't think I'd want to try to calculate > sales tax this way!!) ;-) - Bob