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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,9fa5063fbdc75ae4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-16 07:30:52 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!rwcrnsc54.POSTED!not-for-mail Message-ID: <3F8EAB8F.8040901@comcast.net> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: array of strings in a function References: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc54 1066314651 24.34.139.183 (Thu, 16 Oct 2003 14:30:51 GMT) NNTP-Posting-Date: Thu, 16 Oct 2003 14:30:51 GMT Organization: Comcast Online Date: Thu, 16 Oct 2003 14:30:51 GMT Xref: archiver1.google.com comp.lang.ada:984 Date: 2003-10-16T14:30:51+00:00 List-Id: Antonio Mart�nez �lvarez wrote: > Hello again. I'm the original poster. > > What I want to do is a procedure (sorry, not a function) to do something > like this: > > my_AND("Entrada_1", "P2", "Output"); > > and with this argument, this function have to write this: > > entity my_AND is port( > Entrada_1 : in std_logic; > P2 : in std_logic; > Output : out std:logic; > ); > > (This is VHDL code, very similar to Ada95). Now it becomes clear. You need a way to "wrap-up" names passed as strings and unwrap them into the original strings inside the procedure. The idea of declaring a procedure with a lot of String parameters all with default values denoting that the parameter is not used can work. But it is conceptually ugly. A better way is to define a type: 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; 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; function "+"(Left, Right: String) return Parameter_List is Temp: String(1..Left'Length) := Left -- slide Left if necessary; begin return Temp & '+' & Right; end "+"; function "+"(Left: Parameter_List; Right: String) return Parameter_List; begin return Left & '+' & Right; end "+"; 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; 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; Of course, this would mean that users couldn't have "+" in their name strings. So you might want to use a marker such as Ada.Characters.Latin_1.Reserved_128. That can't accidently appear in a string literal. Or Ada.Characters.Latin1.No_Break_Space. ;-) -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig