comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: U : Unbounded_String := "bla bla bla"; (was: Is the Writing...)
Date: Wed, 08 Oct 2003 23:18:59 GMT
Date: 2003-10-08T23:18:59+00:00	[thread overview]
Message-ID: <3F849B4A.2090008@comcast.net> (raw)
In-Reply-To: mailman.36.1065484926.25614.comp.lang.ada@ada-france.org

Alexandre E. Kopilovitch wrote:

> BTW, when you mentioned Cyrillic_String you made me smiling grimly. Do you
> know that there are 3 alive Cyrillic encodings? Do you know that, for example,
> in Windows, the final effect of your Cyrillic encoding depends not only upon
> encoding, but upon Regional Settings also? And there are plenty of more subtle
> issues, which may easily hurt you when you deal with a Cyrillic encoding. So,
> don't fancy that your Cyrillic_String will be of much help, especially if you
> want to develop a robust product for actual field use.

You are just thinking Russian, there are even more Cyrillic character 
bindings for other Cyrillic languages.  When it comes to multiple 
representations for one language Japanese is by far the worst!  But if 
you don't see it, try this.  In Ada, I can DEFINE a Cyrillic_String type 
and bind it to one of the variants, and add other string types for other 
variants, then provide for conversions between them.  The fact that 
almost all conversions are explicit makes all this possible.  Let me add 
three types and show you the problem:

   type Unbounded_Cyrillic is new Ada.Strings.Unbounded.Unbounded_String;
   -- to make sure you don't get confused.  Yeah, I know, in real life
   -- you should make the derivation private, and provide Cyrillic_String
   -- versions of some of the operations in Ada.Strings.Unbounded.  Take
   --- all that as given.
   type Georgian_String is (...);
   type Unbounded_Georgian is new Ada.Strings.Unbounded.Unbounded_String;
   -- same as above.

   In Ada as it is now, I can say:

   Some_String: Unbounded_Cyrillic := To_Unbounded("Македонии");
   Other_String: Unbounded_Georgian := To_Unbounded("Македонии");

In each case, there is an implicit conversion from the string_literal 
"Македонии" to the proper string type, then that type is converted to 
the proper unbounded type.  But if you add additional implicit 
conversions into the mix, it all falls apart:

   Some_String: Unbounded_Cyrillic := "Македонии";

I hope you don't expect the compiler to guess which set of implicit 
conversions to apply!  I am certainly not going to try to list all the 
possibilities, but for example, there is: "Македонии" to String to 
Unbounded_String to Cyrillic_String.  And yes, in this case, the first 
conversion would raise Constraint_Error.  But I could choose some other 
example where all the characters were in both (Latin1) String and 
Cyrillic_String.  But I don't have to: "Македонии" to Georgian_String to 
Unbounded_Georgian to Unbounded_String to Cyrillic_String.

Once you introduce new implicit conversions, the compiler is going to 
have to assume that they may occur anywhere.  If the overloading rules 
result in only one possible match, great.  But you will find that right 
now Ada has about as many implicit conversions as it can without 
creating lots of ambiguous situations.  And yes, there are situations in 
Ada currently where you have to qualify expressions to avoid ambiguity. 
The most userul balance point is where everything can be done, and you 
don't have to qualify expressions too often.

Oh, since I am trying to be fair here, there is one additional implicit 
conversion that I would love to figure out how to add to the language. 
(Well, I know how to add it, I just don't think I'll ever get enough 
interest to make it happen.)  That would be to add some pragmas that 
allowed  character, string, or numeric literals to private types.  The 
conversion directly from a character literal to Unbounded_Cyrillic 
wouldn't break anything.  It also wouldn't help if you had a 
Cyrillic_String variable to put in an Unbounded_Cyrillic object.


-- 
                                          Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




  parent reply	other threads:[~2003-10-08 23:18 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-02 18:02 U : Unbounded_String := "bla bla bla"; (was: Is the Writing...) amado.alves
2003-10-03  0:05 ` U : Unbounded String : " Alexander Kopilovitch
2003-10-03 20:46   ` Dmitry A. Kazakov
2003-10-03  9:00 ` U : Unbounded_String := " Preben Randhol
2003-10-03 11:17   ` Jeff C,
2003-10-04  2:49     ` Robert I. Eachus
2003-10-06 23:57       ` Alexandre E. Kopilovitch
2003-10-07  8:51         ` Dmitry A. Kazakov
2003-10-08 19:12           ` Alexandre E. Kopilovitch
2003-10-09  8:42             ` Dmitry A. Kazakov
2003-10-10 20:58               ` Alexander Kopilovitch
2003-10-13  8:35                 ` Dmitry A. Kazakov
2003-10-13 21:43                   ` Alexandre E. Kopilovitch
2003-10-14  8:09                     ` Dmitry A. Kazakov
2003-10-16  9:39                       ` Alexandre E. Kopilovitch
2003-10-18 10:57                         ` Dmitry A. Kazakov
2003-10-08 23:18         ` Robert I. Eachus [this message]
2003-10-09 21:35           ` Alexandre E. Kopilovitch
2003-10-10 18:10             ` Robert I. Eachus
2003-10-11 19:43               ` Alexandre E. Kopilovitch
2003-10-12  5:03                 ` Robert I. Eachus
2003-10-13  9:07                   ` Dmitry A. Kazakov
2003-10-13 14:36                   ` Alexandre E. Kopilovitch
2003-10-13 19:46                     ` Robert I. Eachus
2003-10-14  1:35                       ` Jeffrey Carter
2003-10-14 17:11                       ` Alexandre E. Kopilovitch
2003-10-14 20:26                         ` Mark A. Biggar
2003-10-14 20:58                           ` Robert I. Eachus
2003-10-15 16:59                           ` Alexandre E. Kopilovitch
2003-10-15 20:38                             ` (see below)
2003-10-16  0:31                               ` Alexandre E. Kopilovitch
2003-10-16  2:30                                 ` (see below)
2003-10-16 13:54                                   ` Alexandre E. Kopilovitch
2003-10-16 14:11                                     ` (see below)
2003-10-16  8:01                             ` Dmitry A. Kazakov
2003-10-17 20:26                   ` Randy Brukardt
2003-10-17 21:39                     ` Alexandre E. Kopilovitch
2003-10-17 23:03                     ` Robert I. Eachus
2003-10-23 21:11                       ` Alexandre E. Kopilovitch
  -- strict thread matches above, loose matches on Subject: below --
2003-10-03 12:00 amado.alves
2003-10-03 15:54 ` Mark A. Biggar
2003-10-03 20:41 ` Dmitry A. Kazakov
2003-10-03 16:12 amado.alves
2003-10-04 12:16 ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox