comp.lang.ada
 help / color / mirror / Atom feed
From: John Smith <yoursurrogategod@gmail.com>
Subject: Re: Multiple procedures in the same adb file?
Date: Sun, 11 Jan 2015 12:38:17 -0800 (PST)
Date: 2015-01-11T12:38:17-08:00	[thread overview]
Message-ID: <d8553a61-91a3-4967-8fd1-5698373c7d43@googlegroups.com> (raw)
In-Reply-To: <wcc1tn1m6yr.fsf@shell01.TheWorld.com>

Hello Bob,

Thanks, that was really helpful.  I got it to work by making the appropriate *.ads and *.adb files.  I also had it working as a nested function.

It seems a tad tedious at first, but it does make sense.  Heck, even C/C++ recommends a similar approach.  You want to separate the declaration from the implementation.

On Sunday, January 11, 2015 at 2:51:32 PM UTC-5, Robert A Duff wrote:
> John Smith <you...@gmail.com> writes:
> 
> > I have a question, what if I want multiple procedures in the same adb
> > file, can that be done?  ...
> 
> The simplest thing is to have a single procedure that is your main
> procedure, and everything else in packages or generic packages.
> The main procedure goes in one file, and each package spec and each
> package body in a separate file.  The naming convention is x.ads for
> specs and x.adb for bodies, where x is the name of the compilation_unit
> (i.e. the package spec or body or procedure body).
> 
> You don't have to do that.  There are ways to use different naming
> conventions, put multiple compilation units in one files, etc,
> but they are a nuisance.  Look up gnatchop, pragma Source_File_Name,
> and project files if you really want to do it differently than
> the standard GNAT way.
> 
> The main procedure doesn't need a spec, but it can have one.
> It is unwise to have procedures outside of packages (other than the
> main procedure, which Ada annoyingly doesn't allow to be in a package).
> 
> For medium-to-large programs, use child packages.  A single root package
> (or small number of them), with everything else being child, grandchild,
> and so on of the root(s).  The main procedure can be a root, or can be a
> child of your single root package.
> 
> > ===============================================================================
> > procedure a_test(A, B : Integer; C : out Integer) is
> > begin
> >   C := A + B;
> > end a_test;
> >
> > procedure test_procedure is
> >   output : Integer;
> > begin
> >   a_test(23, 34, output);
> > end test_procedure;
> > ===============================================================================
> 
> Note that you could nest a_test inside test_procedure.
> 
> It's a good idea to follow common style rules, such as calling those
> A_Test and Test_Procedure.  (But the file names should be in lower
> case.)
> 
> - Bob

  reply	other threads:[~2015-01-11 20:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-11 18:37 Multiple procedures in the same adb file? John Smith
2015-01-11 19:05 ` John Smith
2015-01-11 19:51 ` Robert A Duff
2015-01-11 20:38   ` John Smith [this message]
2015-01-11 21:02     ` Robert A Duff
2015-01-11 21:51       ` John Smith
2015-01-12  0:53         ` Robert A Duff
2015-01-12  0:55         ` Robert A Duff
2015-01-13  0:11       ` Randy Brukardt
2015-01-11 21:38   ` Niklas Holsti
2015-01-12  0:53     ` Robert A Duff
2015-01-12  9:01       ` J-P. Rosen
2015-01-12 14:57         ` Robert A Duff
2015-01-13  0:09           ` Randy Brukardt
2015-01-12  0:55     ` Robert A Duff
2015-01-11 20:04 ` Jeffrey Carter
replies disabled

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