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,WEIRD_QUOTING 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 02:31:23 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.clear.net.nz!news.clear.net.nz.POSTED!not-for-mail NNTP-Posting-Date: Thu, 16 Oct 2003 04:31:22 -0500 From: Craig Carey Newsgroups: comp.lang.ada Subject: Re: array of strings in a function Date: Thu, 16 Oct 2003 22:31:23 +1300 Message-ID: <8unsov8a3r9p02lm0ftkmmget77esc7fv7@4ax.com> References: X-Newsreader: Forte Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Organization: Customer of Mercury Telecommunications Ltd Cache-Post-Path: drone5.qsi.net.nz!unknown@tnt1-8.quicksilver.net.nz X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/) X-Original-NNTP-Posting-Host: drone5-svc-skyt.qsi.net.nz X-Original-Trace: 16 Oct 2003 22:31:31 +1300, drone5-svc-skyt.qsi.net.nz NNTP-Posting-Host: 203.97.37.6 X-Trace: sv3-2IYD4VshOqHPk7prQ1xeA58NfPahBytIKswlSk0ROkZzgr+fKbP9AKPjCAQ+eWYS7kiy3cwMo1Es9Cg!6R68EAjRQ2Z1BszQz9+/W9TGF+NcNTWixC7J8csBiWueXdAbPY/QmoM5yYtmlx9lZPc2CvjoLTAJ!Altlzvo= X-Complaints-To: Complaints to abuse@clear.net.nz X-DMCA-Complaints-To: Complaints to abuse@clear.net.nz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:961 Date: 2003-10-16T22:31:23+13:00 List-Id: Functions with varying numbers of arguments are handled by Ada 95: construct an array of pointers at the place the procedure is called: ----- with Text_IO; with Ada.Unchecked_Deallocation; procedure Main is type String_Ptr is access all String; type SPA is array (Positive range <>) of String_Ptr; procedure Deallocate is new Ada.Unchecked_Deallocation ( Object => String, Name => String_Ptr); function "+" (X : String) return String_Ptr is begin return new String'(X); end "+"; procedure Varargs (U : SPA) is Tmp : String_Ptr; begin Text_IO.Put ("Got : "); for K in U'Range loop Text_IO.Put ("""" & String (U (K).all) & """"); if K /= U'Last then Text_IO.Put (", "); end if; Tmp := U (K); Deallocate (Tmp); -- No memory leak end loop; Text_IO.Put_Line ("."); end Varargs; G : String := "Efgh"; begin Varargs (SPA'(1 => +"Abc", 2 => +G, 3 => +"Last")); end Main ----- The output: | Got : "Abc", "Efgh", "Last". Syntax errors are a problm when the heap is not used (a GNAT pointer to a string is 64 bits and twice the size of a pointer to a record). On Thu, 16 Oct 2003 06:40:26 GMT, tmoran@acm.org wrote: ... > But you can certainly have a set of subprograms with the same name >but differing number of parameters: ... At Wed, 15 Oct 2003 13:49:42 +0200, Antonio Mart�nez wrote: Subject: Re: array of strings in a function [from comp.lang.ada-@-ada-france.org ] >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). > > In general, I don't know the number of string arguments. ... Is that a parser project?. Adagoop and Ayacc are options: ftp://ftp.usafa.af.mil/pub/dfcs/carlisle/usafa/adagoop/index.html http://www.mysunrise.ch/users/gdm/gsoft.htm -- Craig Carey