comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: conversion
Date: Wed, 09 Jul 2003 09:42:27 +0200
Date: 2003-07-09T09:42:27+02:00	[thread overview]
Message-ID: <d2gngvk9li9mm0o563b5o6lhrqgb1vccur@4ax.com> (raw)
In-Reply-To: 3F03D54C.7010008@attbi.com

On Thu, 03 Jul 2003 07:03:43 GMT, "Robert I. Eachus"
<rieachus@attbi.com> wrote:

>Dmitry A. Kazakov wrote:
>
>> If you mean that unversal integer is something like String, then you
>> are probably right. But the difference is that we cannot declare
>> objects of universal integer. On contrary, for strings we can, but
>> surprisingly that type is called "Unbounded_String" and even more
>> surprising is that it is unrelated to String.
>
>No! No! No!  You are very confused.  First of all, what do you think the 
>type of Foo is in:
>
>   Foo: constant := 123456789012;
>
>(Actually in Ada 95 it is _root_integer_ while the literal 123456789012 
>is of type _universal_integer_, but that is a detail. (_root_integer_ 
>includes all other integer types, including _universal_integer_.)

This is what I meant. You can consider string literals as being of
some unversal string type. Then you can have some parent string type
for all string types. Call it root string if you want. The hierarchy
might look like:

root string
   universal string = Unbounded_String
      String
      Bounded_String
      user-defined strings with literals
   user-defined strings with no literals

>The Integer type that corresponds most closely to String, is Integer, 
>and they are both declared in Standard.

It does not. Because Integer is constrained.

>> It is clear (isn't it) that all different string types have same
>> semantics and differ only in how they implement that semantics. So
>> they should be related.
>
>Yes, so the three different implementations are all clustered under 
>Ada.Strings: Ada.Strings.Fixed, Ada.Strings.Bounded, and 
>Ada.Strings.Unbounded.

This does not help. Types have to be related, order of packages is
rather a cosmetic thing.

> >                             That length of a String value cannot be
> > changed is just a value constraint which by no means changes string
> > semantics.
>
>No. String values are never constrained, String objects are always 
>constrained, often by their initial values.  If I have a function that 
>may return a different length string every time it is called, and that 
>length is unpredictable in advance?  That is not a problem, it is a 
>common idiom:
>
>     while not Done loop
>       declare
>         Buffer: String := Get_Line;
>       begin
>         -- process Buffer...
>       end;
>     end loop;

You missed the point. String as a concept has a semantics which allows
*any* values. That String as a type implementing  the concept has
values constrained in some special way, does not change that
semantics.

>There is no static/dynamic dichotomy here, nor is there a 
>bounded/unbounded distinction, or even constrained/unconstrained. 
>Buffer is always constrained to be the same length as the String 
>returned by the most recent call to Get_Line.  (Unfortunately that 
>function is not Ada.Text_IO.Get_Line, but I hope we will fix that next 
>time around.)

Yes.

>> So instead of looking for explanations which I doubt would convince
>> anybody, one could simply admit that, yes, String and Unbounded_String
>> should be better siblings, but to do it consistently would require too
>> many changes Ada's ADT model.
>
>Ada.Strings.Fixed, Ada.Strings.Bounded, and Ada.Strings.Unbounded are 
>the siblings.
>It may bother you that Ada.Strings.Fixed reuses String, 
>and Ada.Strings.Bounded is a generic package you have to instantiate, 
>but those are not the issues you are describing here.
>
>> For example, what would happen if
>> 
>>    type Name is new Unbounded_String;
>> 
>> Should it produce a new String type? Surely. How should it be named?
>> Who knows.
>
>It would be named Name, unless I am missing something, just as:
>
>type New_String is new String;
>
>Creates a new string type named New_String.  Or if you prefer:
>
>type New_String is array(Positive range <>) of Character;
>pragma Pack(String);
>
>Do that in Ada and you will find that you get a type with literals like 
>"foo"...  String is not a priviledged type in Ada.  You can even create 
>a new character type--Character is similarly not special.  For example 
>you could create a Cyrillic character type which used ISO 8859/5 
>Latin/Cyrillic with the upper and lower pages reversed.  Or whatever.  A 
>character type is an enumeration type with character literals.  A string 
>type is any array of any character type.

The problem is. Should String and Unbounded_String be siblings
(descendants of same base), or better, as many would rightfully
expect, String be *both* a subtype and a supertype of
Unbounded_String, then we will have a lot of problems to solve.
Because ADT in Ada is presently unable to deal with that.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-07-09  7:42 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-27 10:51 conversion Andrew
2003-06-27 12:22 ` conversion Dmitry A. Kazakov
2003-06-27 12:37 ` conversion Stephen Leake
2003-06-27 14:26   ` conversion Bill Findlay
2003-06-27 17:04     ` conversion Georg Bauhaus
2003-07-04  0:21     ` conversion Dave Thompson
2003-06-27 13:25 ` conversion Robert I. Eachus
2003-06-27 18:42   ` conversion tmoran
2003-06-27 14:49 ` conversion Matthew Heaney
2003-06-27 17:10 ` conversion Georg Bauhaus
2003-06-27 17:13 ` conversion Alexander Kopilovitch
2003-06-27 17:34   ` conversion Preben Randhol
2003-06-27 22:10     ` conversion Alexander Kopilovitch
2003-06-28  9:46       ` conversion Preben Randhol
2003-06-27 22:13   ` conversion Robert I. Eachus
2003-06-30  8:52     ` conversion Dmitry A. Kazakov
2003-07-03  7:03       ` conversion Robert I. Eachus
2003-07-09  7:42         ` Dmitry A. Kazakov [this message]
2003-07-09 17:04           ` conversion Robert I. Eachus
2003-07-10 10:19             ` conversion Dmitry A. Kazakov
2003-07-11  1:56               ` conversion Alexander Kopilovitch
2003-07-05  2:40     ` conversion Alexander Kopilovitch
2003-07-05  6:33       ` conversion Georg Bauhaus
2003-07-05 17:06         ` conversion Alexander Kopilovitch
2003-07-06  3:53           ` conversion Robert I. Eachus
2003-07-06  5:13             ` conversion Jeffrey Carter
2003-07-06 12:45               ` conversion Chad R. Meiners
2003-07-07  1:09             ` conversion Alexander Kopilovitch
2003-07-06 20:04           ` conversion Georg Bauhaus
2003-07-07 14:55             ` conversion Stephen Leake
2003-07-07 21:36               ` conversion Alexander Kopilovitch
     [not found] <002701c33e22$8e9deaf0$0201a8c0@win>
2003-06-29 20:15 ` conversion David C. Hoos, Sr.
  -- strict thread matches above, loose matches on Subject: below --
2003-06-29  9:41 conversion Andrew
2003-07-04 10:42 ` conversion Janeit
2003-06-28  8:46 conversion Andrew
2003-06-28  9:49 ` conversion Preben Randhol
2003-06-30 14:08 ` conversion Stephen Leake
2003-06-27 17:37 conversion Andrew
2003-06-27 17:32 ` conversion Stephen Leake
2003-06-28  2:55 ` conversion Jeffrey Carter
1998-07-22  0:00 conversion Rick
1998-07-22  0:00 ` conversion Richard Toy
1998-07-22  0:00 ` conversion Corey Ashford
1998-07-22  0:00   ` conversion Corey Ashford
replies disabled

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