comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: conversion
Date: Sun, 06 Jul 2003 03:53:03 GMT
Date: 2003-07-06T03:53:03+00:00	[thread overview]
Message-ID: <3F079D10.2060709@attbi.com> (raw)
In-Reply-To: e2e5731a.0307050906.227e945f@posting.google.com

Alexander Kopilovitch wrote:

>   /* C/C++ example */
> 
>   char *Titles[] = {
>                     "Quizionary",
>                     "Nose To Nose",
>                     "Myself",
>                     "General Dissent",
>                     "Veteran's Opinion",
>                     "Corporate Science Weekly",
>                     "Truth, Wealth, Health",
>                     "Bribery Times"
>                    };
> 
> 
>   { Object Pascal example }
>                                                 
>   const
>         Dishes : array [1..4] of String = (
>                                            'black pudding',
>                                            'crab soup',
>                                            'steak & kidney pie',
>                                            'lemon tart'
>                                           );

Two examples.  One without any Ada support packages, and one that uses
Ada.Strings.Bounded.  Personally I think that during standarization, to 
much was added in, and as a result, Ada.Strings.Bounded is harder to use 
than it should be.  But of course, you can roll your own, the way you 
had to in Ada 83.

But notice two major differences between the Ada way, and the C and 
Pascal way.  The Ada solutions are built around standard Ada features, 
not special case features, and the Ada solution allows for non-constant 
arrays, in fact the individual elements can change in length. (Yes, I 
know that in the C++ case you can assign other pointers, but the 
original values can't be modified as such.)

procedure Varying is -- an example of how to create ragged arrays in Ada.

   subtype Lim_Int is Integer range 0..30;
   type Inner(L: Lim_Int := 0) is record S: String(1..L); end record;
   type Wrapper is record I: Inner; end record;
   type Ragged_Array is array (Integer range <>) of Wrapper;

   function "+" (S: in String) return Wrapper is
   begin return (I =>(S'Length, S)); end "+";

   function "+" (W: in Wrapper) return String is
   begin return W.I.S; end "+";

   Dishes: Ragged_Array := (+"black pudding",
                            +"crab soup",
                            +"steak & kidney pie",
                            +"lemon tart");

   Titles: Ragged_Array := (+"Quizionary",
                            +"Nose To Nose",
                            +"Myself",
                            +"General Dissent",
                            +"Veteran's Opinion",
                            +"Corporate Science Weekly",
                            +"Truth, Wealth, Health",
                            +"Bribery Times");

begin null; end Varying;

with Ada.Strings.Bounded;
procedure Varying2 is -- an example of how to use Ada.Strings.Bounded.

   package Bounded_Str is new
              Ada.Strings.Bounded.Generic_Bounded_Length(30);

   subtype Bounded_String is Bounded_Str.Bounded_String;

   function "+" (S: in String) return Bounded_String
   is begin return
        Bounded_Str.To_Bounded_String(S, Ada.Strings.Error);
   end "+";

   function "+" (B: in Bounded_String) return String renames
        Bounded_Str.To_String;

   type Ragged_Array is array (Integer range <>) of Bounded_String;

   Dishes: Ragged_Array := (+"black pudding",
                            +"crab soup",
                            +"steak & kidney pie",
                            +"lemon tart");

   Titles: Ragged_Array := (+"Quizionary",
                            +"Nose To Nose",
                            +"Myself",
                            +"General Dissent",
                            +"Veteran's Opinion",
                            +"Corporate Science Weekly",
                            +"Truth, Wealth, Health",
                            +"Bribery Times");

begin null; end Varying2;

-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




  reply	other threads:[~2003-07-06  3:53 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         ` conversion Dmitry A. Kazakov
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           ` Robert I. Eachus [this message]
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