comp.lang.ada
 help / color / mirror / Atom feed
* Ada 83 versions of Ada 95 packages
@ 1996-12-23  0:00 W. Wesley Groleau (Wes)
  1996-12-24  0:00 ` johnherro
  0 siblings, 1 reply; 8+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-12-23  0:00 UTC (permalink / raw)



I recently had to implement in Ada 83 some capabilities that are part of
the Ada 95 standard libraries.  To make future upgrades easier, I decided
to mimic as closely as possible the LRM-required specs.

I recognize that I might have to do something like that again.  Is anyone
else doing anything similar?  If so, are you interested in collaboration,
i.e., sharing the work (assuming management doesn't panic at the thought)?

---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Hughes Defense Communications (MS 10-41)                 Home: 219-471-7206
Fort Wayne,  IN   46808                  (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-23  0:00 Ada 83 versions of Ada 95 packages W. Wesley Groleau (Wes)
@ 1996-12-24  0:00 ` johnherro
  1996-12-24  0:00   ` Robert Dewar
  1996-12-26  0:00   ` Keith Thompson
  0 siblings, 2 replies; 8+ messages in thread
From: johnherro @ 1996-12-24  0:00 UTC (permalink / raw)



"W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM> writes:
>I recently had to implement in Ada 83 some
>capabilities that are part of the Ada 95 standard
>libraries...  Is anyone else doing anything similar?

To a *very small extent* I did something similar by writing a very small
package in Ada 83, which I am happy to contribute to the public domain:
----------
package Ada83_Strings_Unbounded is
   type Unbounded_String(Length : Integer := 0) is private;
   function "+"(Right : in String) return Unbounded_String;
   function "+"(Right : in Unbounded_String) return String;
   function "&"(Left, Right : in Unbounded_String) return
Unbounded_String;
private
   type Unbounded_String(Length : Integer := 0) is
      record
         Text : String(1 .. Length);
      end record;
end Ada83_Strings_Unbounded;

package body Ada83_Strings_Unbounded is
   function "+"(Right : in String) return Unbounded_String is
      Ans : Unbounded_String(Right'Length);
   begin
      Ans.Text := Right;
      return Ans;
   end "+";

   function "+"(Right : in Unbounded_String) return String is
   begin
      return Right.Text;
   end "+";

   function "&"(Left, Right : in Unbounded_String) return Unbounded_String
is
   begin
      return +((+Left) & (+Right));
   end "&";
end Ada83_Strings_Unbounded;
----------
Admittedly this package is very small, but to take slices and do other
functions, you can easily convert from Unbounded_String to String first. 
E.g., if U is an Unbounded_String, you can write "+"(U)(1 .. 3) to take a
slice.  I find this package very useful, and hope others will, too.

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-24  0:00 ` johnherro
@ 1996-12-24  0:00   ` Robert Dewar
  1996-12-24  0:00     ` johnherro
  1996-12-26  0:00   ` Keith Thompson
  1 sibling, 1 reply; 8+ messages in thread
From: Robert Dewar @ 1996-12-24  0:00 UTC (permalink / raw)



johnherro proposed

package Ada83_Strings_Unbounded is
   type Unbounded_String(Length : Integer := 0) is private;
   function "+"(Right : in String) return Unbounded_String;
   function "+"(Right : in Unbounded_String) return String;
   function "&"(Left, Right : in Unbounded_String) return
Unbounded_String;
private
   type Unbounded_String(Length : Integer := 0) is
      record
         Text : String(1 .. Length);
      end record;
end Ada83_Strings_Unbounded;


This is confusingly named. The type involved is more like a fixed string
than an unbounded string, so it is confusing to reuse the Ada 95 name
in a completely misleading manner (especially given the subject line of
this thread!)

You can probably fairly easily adapt the GNAT unbounded string package to
Ada 83, with the following notes:

a. Of course the name of the package has to be changed

b. you cannot use controlled, so that means you probably want to add an
   explicit free operation (in practice this will be the biggest difference
   between Ada 83 and Ada 95 versions of this package).

Otherwise, you should be able to use these packages more or less directly!





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-24  0:00   ` Robert Dewar
@ 1996-12-24  0:00     ` johnherro
  1996-12-24  0:00       ` Norman H. Cohen
  1996-12-24  0:00       ` Robert Dewar
  0 siblings, 2 replies; 8+ messages in thread
From: johnherro @ 1996-12-24  0:00 UTC (permalink / raw)



dewar@merv.cs.nyu.edu (Robert Dewar) writes:
>This is confusingly named. The type involved is
>more like a fixed string than an unbounded string...
I agree that the name of my package may be confusing, because what I
really wrote was a *substitute* for unbounded strings for use with an Ada
83 compiler.  I still hope that the package will prove useful to others.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-24  0:00     ` johnherro
@ 1996-12-24  0:00       ` Norman H. Cohen
  1996-12-25  0:00         ` johnherro
  1996-12-24  0:00       ` Robert Dewar
  1 sibling, 1 reply; 8+ messages in thread
From: Norman H. Cohen @ 1996-12-24  0:00 UTC (permalink / raw)



johnherro@aol.com wrote:

> I agree that the name of my package may be confusing, because what I
> really wrote was a *substitute* for unbounded strings for use with an Ada
> 83 compiler.  I still hope that the package will prove useful to others.

But a discriminant named Length with no default value suggests that
every object of the type will be constrained to a particular length. 
Thus there is no way to implement procedures such as Append,
Replace_Slice, and Delete that modify their Unbounded_String
parameters.  That is what Robert Dewar meant when he said that this
looked like a fixed-length-string type.

The natural way to implement Unbounded_String in Ada 83 is with an
access-to-String type (adding an explicit Free operation as Robert
suggested).  

The natural way to implement a Bounded_String type in Ada 83 is with a
record consisting of a fixed-length string (whose length is the maximum
length for the type) and a current-length component; Bounded_String
should be limited so that its "=" can be overridden to ignore string
components that are present in the record but not logically part of the
value.  This means you will have to provide a Copy operation to replace
assignment, but that's desirable anyway to avoid unneeded copying.  ("="
can be overridden for limited or nonlimited types in Ada 95, but only
for limited types in Ada 83.)

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-24  0:00     ` johnherro
  1996-12-24  0:00       ` Norman H. Cohen
@ 1996-12-24  0:00       ` Robert Dewar
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1996-12-24  0:00 UTC (permalink / raw)



iJohn Herro said

"I agree that the name of my package may be confusing, because what I
really wrote was a *substitute* for unbounded strings for use with an Ada
83 compiler.  I still hope that the package will prove useful to others.
- John Herro"


Sure, and it is a reasonable data structure, but it is not what
unbounded strings are about. If you want an Ada 83 substitute for
unbounded strings, you can certainly have one that is identical to
the Ada 95 semantics with the exception of the automatic storage
finalization.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-24  0:00       ` Norman H. Cohen
@ 1996-12-25  0:00         ` johnherro
  0 siblings, 0 replies; 8+ messages in thread
From: johnherro @ 1996-12-25  0:00 UTC (permalink / raw)



"Norman H. Cohen" <ncohen@watson.ibm.com> writes:
>The natural way to implement a Bounded_String type
>in Ada 83 is with a record consisting of a fixed-length
>string (whose length is the maximum length for the type)
>and a current-length component.
Yes, and that's exactly what the Ada 83 LRM suggested with its
Text_Handler package.  The LRM supplies only the specification, but
writing the body is less than an hour's work, and some Ada 83 compilers
(such as Meridian AdaVantage) come with Text_Handler all ready to use.

With my "pseudo unbounded strings" package, you can at least do this:
Months : array(1 .. 12) of Unbounded_String := (+"January", +"February"
... );
N : Integer := 5;
...
Put_Line(+Months(N));
N(5) := +"The merry, merry month of May";
Put_Line(+Months(N));

However, you're right.  To implement Append, etc., you probably first have
to convert to String, storing the result in a string that you know is long
enough.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Ada 83 versions of Ada 95 packages
  1996-12-24  0:00 ` johnherro
  1996-12-24  0:00   ` Robert Dewar
@ 1996-12-26  0:00   ` Keith Thompson
  1 sibling, 0 replies; 8+ messages in thread
From: Keith Thompson @ 1996-12-26  0:00 UTC (permalink / raw)



In <19961224155500.KAA09943@ladder01.news.aol.com> johnherro@aol.com writes:
[...]
> package Ada83_Strings_Unbounded is
>    type Unbounded_String(Length : Integer := 0) is private;
[...]
> private
>    type Unbounded_String(Length : Integer := 0) is
>       record
>          Text : String(1 .. Length);
>       end record;
> end Ada83_Strings_Unbounded;
[...]

Given this type declaration, with a default value for the discriminant,
an object of type Unbounded_String can occupy Integer'Last bytes (under
most compilers).

-- 
Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
"SPOON!" -- The Tick




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1996-12-26  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-23  0:00 Ada 83 versions of Ada 95 packages W. Wesley Groleau (Wes)
1996-12-24  0:00 ` johnherro
1996-12-24  0:00   ` Robert Dewar
1996-12-24  0:00     ` johnherro
1996-12-24  0:00       ` Norman H. Cohen
1996-12-25  0:00         ` johnherro
1996-12-24  0:00       ` Robert Dewar
1996-12-26  0:00   ` Keith Thompson

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