From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9fa5063fbdc75ae4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-16 10:53:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!nf3.bellglobal.com!sjc70.webusenet.com!news.webusenet.com!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: array of strings in a function References: <3F8EAB8F.8040901@comcast.net> In-Reply-To: <3F8EAB8F.8040901@comcast.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 16 Oct 2003 17:53:48 GMT NNTP-Posting-Host: 63.184.9.21 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1066326828 63.184.9.21 (Thu, 16 Oct 2003 10:53:48 PDT) NNTP-Posting-Date: Thu, 16 Oct 2003 10:53:48 PDT Xref: archiver1.google.com comp.lang.ada:1004 Date: 2003-10-16T17:53:48+00:00 List-Id: 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