comp.lang.ada
 help / color / mirror / Atom feed
From: agent@drrob1.com
Subject: Re: need help learning Ada for a modula-2 programmer
Date: Sun, 02 Feb 2014 10:02:20 -0500
Date: 2014-02-02T10:02:20-05:00	[thread overview]
Message-ID: <2rmse99q9qtgb9g7edoavse53p74f4p0ak@4ax.com> (raw)
In-Reply-To: lcknei$tnu$1@dont-email.me

On Sat, 01 Feb 2014 23:09:16 -0700, Jeffrey Carter
<spam.jrcarter.not@spam.not.acm.org> 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

  reply	other threads:[~2014-02-02 15:02 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-28  1:06 need help learning Ada for a modula-2 programmer agent
2014-01-28  1:33 ` adambeneschan
2014-01-28  1:52 ` Jeffrey Carter
2014-01-28 12:18 ` Brian Drummond
2014-02-02  2:47   ` agent
2014-02-02  6:09     ` Jeffrey Carter
2014-02-02 15:02       ` agent [this message]
2014-02-02 16:00         ` gautier_niouzes
2014-02-02 19:48         ` Jeffrey Carter
2014-02-03  8:24           ` Dmitry A. Kazakov
2014-02-02 17:18     ` Brian Drummond
2014-02-03  0:10       ` agent
2014-02-03  0:36         ` agent
2014-02-03 12:53         ` Brian Drummond
2014-01-28 22:51 ` Jerry
2014-01-29 12:15   ` Mike H
2014-01-29 20:41     ` Jacob Sparre Andersen
2014-01-29 23:52       ` Jeffrey Carter
2014-01-30  9:05         ` Jacob Sparre Andersen
2014-01-30 14:20       ` Mike H
2014-01-30 14:35         ` Bill Findlay
2014-01-30 15:40           ` Mike H
2014-01-30 23:39         ` Jeffrey Carter
2014-01-31 20:16           ` Mike H
2014-01-29 23:52     ` Jeffrey Carter
2014-01-30  1:44       ` Bill Findlay
2014-01-30  2:01         ` Jeffrey Carter
2014-01-30 12:24       ` Simon Wright
2014-01-30 23:38         ` Jeffrey Carter
2014-02-03 23:12     ` agent
2014-02-04  6:10       ` J-P. Rosen
2014-02-04 22:38   ` agent
2014-01-29 16:58 ` Dirk Heinrichs
2014-01-29 20:43   ` Randy Brukardt
2014-01-29 22:53     ` Georg Bauhaus
2014-01-30 12:13       ` Simon Wright
2014-01-30 17:05     ` Dirk Heinrichs
2014-01-30 23:21       ` Randy Brukardt
2014-01-30  4:29   ` Nasser M. Abbasi
2014-01-30  8:45     ` Where to put change descriptions (Was: need help learning Ada for a modula-2 programmer) Jacob Sparre Andersen
2014-01-30  9:53     ` need help learning Ada for a modula-2 programmer Georg Bauhaus
2014-01-30 21:58       ` Randy Brukardt
2014-01-30 16:28     ` Pascal Obry
2014-01-30 17:43       ` Marius Amado-Alves
2014-01-30 18:10       ` Simon Wright
2014-01-30 22:38       ` Randy Brukardt
replies disabled

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