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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-15.dc1.easynews.com.POSTED!not-for-mail From: agent@drrob1.com Newsgroups: comp.lang.ada Subject: Re: need help learning Ada for a modula-2 programmer Message-ID: <2rmse99q9qtgb9g7edoavse53p74f4p0ak@4ax.com> References: User-Agent: ForteAgent/7.20.32.1218 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@easynews.com Organization: Forte Inc. http://www.forteinc.com/apn/ X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Sun, 02 Feb 2014 10:02:20 -0500 X-Received-Bytes: 3250 Xref: news.eternal-september.org comp.lang.ada:18351 Date: 2014-02-02T10:02:20-05:00 List-Id: On Sat, 01 Feb 2014 23:09:16 -0700, Jeffrey Carter wrote: >On 02/01/2014 07:47 PM, agent@drrob1.com wrote: >> >> PROCEDURE GetCommandLine(CommandLine : OUT String) is >> BEGIN >> n := argument_count; >> k := 1; >> >> WHILE k <= n LOOP >> move(argument(k),argstr); - tried this- >> argstr := argument(k); -- and this. Neither works. > >Where is Argstr defined? > >> cmdlinefrag := cmdlinefrag & argstr; > >Same for Cmdlinefrag. > >> I don't understand how to get this working using standard strings. >> This is easy for me using ARRAY OF CHARACTER types in M2 and >> procedures from the Strings standard module. > >The actual length of Commandline is determined by the actual parameter. If you >want to return a String of just the right length, you'll either need an out >parameter of an (Un)Bounded_String type, or a function that returns String. > >For the latter approach, you could use recursion: > >function Command_Line return String is > function Piece (Arg : in Positive) return String is > -- Empty declarative part > begin -- Piece > if Arg > Ada.Command_Line.Argument_Count then > return ""; > elsif Arg = Ada.Command_Line.Argument_Count then > return Ada.Command_Line.Argument (Arg); > else > return Ada.Command_Line.Argument (Arg) & ' ' & Piece (Arg + 1); > end if; > end Piece; >begin -- Command_Line > return Piece (1); >end Command_Line; ArgStr and CmdlineFrag are defined at the module level. The working version of this code declares them to be bounded strings. Brian said that he uses fixed length strings almost always. I am interested in how that could be done. Is it correct that having a function return a fixed string is more flexible than a string param in a procedure? I am getting the sense that having a function return the string on the stack works by not setting its dimensions in advance, but a param has to set them in advance. So the trick is to use the stack for strings by recursion, as you just did? I don't use recursion in my code. This is probably because the first language I learned was Fortran 66, and I never needed it before. With the single exception of the quicksort algorithm. Which I copied from a book. Thx