comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: array of strings in a function
Date: Thu, 16 Oct 2003 17:53:48 GMT
Date: 2003-10-16T17:53:48+00:00	[thread overview]
Message-ID: <MWAjb.3185$s93.1153@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: <3F8EAB8F.8040901@comcast.net>

Robert I. Eachus wrote:


This is good. We've all been dealing with the implementation, and you're 
talking about the abstraction, which is what was missing.

However, we should inspect your proposal.

> type Parameter_List is private;
> 
> the operations to create a parameter list:
> 
> function "+"(Left, Right: String) return Parameter_List;
> function "+"(Left: Parameter_List; Right: String) return Parameter_List;
 >
> and the operations to access the contents of objects of the type:
> 
> function Length(P: Parameter_List) return Integer;
> function Contents(P: Parameter_List; Row: Integer) return String;

So a negative Length is possible? And Contents (P, -27) is meaningful? I 
think Length should return Natural, and Row should be Positive.

> 
> Now any of the techniques suggested for implementing the Parameter_List 
> type will work. Let me, in case it isn't obvious say how you should use 
> the ADT:
> 
>    procedure my_AND(P: Parameter_List);
> begin
>    my_AND("Entrada_1" + "P2" + "Output");
> 
> This call will create Parameter_List with three entries that can be 
> "unwrapped" inside my_AND.
> 
> So how to implement the ADT?  You could make Parameter_List an array of 
> Unbounded_String.  Or you could choose a String with markers:
> 
> type Parameter_List is String;

This is not Ada. And making it "new String" won't work, either, since 
Parameter_List is definite. So this proposal needs some work. Perhaps 
"new Unbounded_String" is better.

> function "+"(Left, Right: String) return Parameter_List is
>   Temp: String(1..Left'Length) := Left -- slide Left if necessary;
> begin return Temp & '+' & Right; end "+";

This returns a String, not a Parameter_List (assuming you convert Left 
to String).

> 
> function "+"(Left: Parameter_List; Right: String) return Parameter_List;
> begin return Left & '+' & Right; end "+";

"&" (Left : Parameter_List; Right : Character) is undefined.

> function Length(P: Parameter_List) return Integer is
>   Count: Integer := 0;
> begin
>   for I in P'Range loop
>     if P(I) = '+' then Count := Count + 1;
>   end loop;
>   return Count;
> end Length;

This seems to return Length - 1, since a list with 2 parameters in it 
will contain one '+'. Since it's not clear what the value of

P : Parameter_List;

is, it's hard to tell what this should do for an empty list.

> function Contents(P: Parameter_List; Row: Integer) is
>   First: Integer := P'First;
>   Last: Integer := P'Last;
>   Count: Integer := 0;
> begin
>   for I in P'Range loop
>     if P(I) = '+'
>     then
>       Count := Count + 1;
>       if Count = Row - 1
>       then First := I+1;
>       elsif Count = Row
>       then Last := I-1;
>         return P(First..Last);
>       end if;
>     end if;
>   end loop;
>   if Count = Row - 1
>   then return P(First..Last); -- last entry not followed by "+"
>   else raise Constraint_Error; -- Row number incorrect
>   end if;
> end Contents;

Something along these lines could work, perhaps using Unbounded_String, 
but I wanted to point out to to the OP that this won't work as given, 
and needs some work.

-- 
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail
10




  reply	other threads:[~2003-10-16 17:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-14 20:54 array of strings in a function Antonio Martínez
2003-10-15  2:55 ` Robert I. Eachus
2003-10-15  3:29   ` Jeff C,
2003-10-15  3:08 ` Jeffrey Carter
2003-10-16  6:40   ` tmoran
2003-10-16  9:31     ` Craig Carey
2003-10-16 18:13       ` Craig Carey
2003-10-16 21:44         ` Marius Amado Alves
2003-10-17 19:48           ` Craig Carey
2003-10-18 10:05             ` Marius Amado Alves
2003-10-18 20:05               ` Craig Carey
2003-10-30  9:42                 ` Craig Carey
2003-10-16 17:58     ` Jeffrey Carter
2003-10-16 20:00       ` tmoran
2003-10-17  0:51         ` Jeffrey Carter
2003-10-15 11:49 ` Antonio Martínez Álvarez
2003-10-15 12:29   ` Preben Randhol
2003-10-15 14:19   ` Ole-Hjalmar Kristensen
2003-10-16 14:30   ` Robert I. Eachus
2003-10-16 17:53     ` Jeffrey Carter [this message]
2003-10-17  0:48       ` Robert I. Eachus
2003-10-17 18:41         ` Jeffrey Carter
replies disabled

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