comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada as 2nd Lang, p. 678
  1997-05-01  0:00 Ada as 2nd Lang, p. 678 John M. Greer
@ 1997-04-30  0:00 ` Matthew Heaney
  1997-05-02  0:00 ` Robert Dewar
  1997-05-12  0:00 ` Norman H. Cohen
  2 siblings, 0 replies; 7+ messages in thread
From: Matthew Heaney @ 1997-04-30  0:00 UTC (permalink / raw)



In article <5k92el$bs9@ultranews.duc.auburn.edu>,
johng@discovery.eng.auburn.edu (John M. Greer) wrote:

You need to separate files.  One for the spec, the other for the body.

file cyclic_successor_template.ads:

>GENERIC
>   TYPE Discrete_Type IS (<>);
>   FUNCTION Cyclic_Successor_Template (X : Discrete_Type) RETURN Discrete_Type;

file cyclic_successor_template.adb:

>   FUNCTION Cyclic_Successor_Template (X:Discrete_Type) RETURN Discrete_Type IS
>   BEGIN
>      IF X = Discrete_Type'Last THEN
>         RETURN Discrete_Type'First;  <<<--- I'm sure you meant 'First,
not ;First
>      ELSE
>         RETURN Discrete_Type'Succ(X);
>      END IF;
>   END Cyclic_Successor_Template;

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Ada as 2nd Lang, p. 678
@ 1997-05-01  0:00 John M. Greer
  1997-04-30  0:00 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: John M. Greer @ 1997-05-01  0:00 UTC (permalink / raw)



I was wondering if anyone could help for a second . . .
Ada as a Second Language (My favorite book) gives this listing
for an example using Generic subprograms, but GNAT complains of end-of-line;
it sees the declaration and stops.
"end of file expected, file can have only one compilation unit
gnatmake: "cyclic_successor_template.adb" compilation error"

GENERIC
   TYPE Discrete_Type IS (<>);
   FUNCTION Cyclic_Successor_Template (X : Discrete_Type) RETURN Discrete_Type;

--Generic subprogram body:

   FUNCTION Cyclic_Successor_Template (X:Discrete_Type) RETURN Discrete_Type IS
   BEGIN
      IF X = Discrete_Type'Last THEN
	 RETURN Discrete_Type;First;
      ELSE
	 RETURN Discrete_Type'Succ(X);
      END IF;
   END Cyclic_Successor_Template;





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada as 2nd Lang, p. 678
  1997-05-01  0:00 Ada as 2nd Lang, p. 678 John M. Greer
  1997-04-30  0:00 ` Matthew Heaney
@ 1997-05-02  0:00 ` Robert Dewar
  1997-05-09  0:00   ` nickerson
  1997-05-12  0:00 ` Norman H. Cohen
  2 siblings, 1 reply; 7+ messages in thread
From: Robert Dewar @ 1997-05-02  0:00 UTC (permalink / raw)



John asks about

<<I was wondering if anyone could help for a second . . .
Ada as a Second Language (My favorite book) gives this listing
for an example using Generic subprograms, but GNAT complains of end-of-line;
it sees the declaration and stops.
"end of file expected, file can have only one compilation unit>>


The message seems clear enough "file can have only one compilation unit",
means that a single file can contain only one compilation unit, and the
file you submitted contains two. The Ada standard says nothing about files,
or how sources are arranged into files, so this is a place that Ada compilers
may differ (some Ada compilers do allow multiple units in a single file).

Actually it is generally a bad idea to do what you did -- put the spec and
the body in the same unit, because that causes an unnecessary connection
between the two. The whole idea in Ada is to separate the spec and the
body, so putting them in separate files is recommended in any case.

If you are using GNAT, then you can either manually split these into two
files, or use gnatchop to do this for you. You really should read the
GNAT documentation. This and many other interesting and useful things
about GNAT are described there!





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada as 2nd Lang, p. 678
  1997-05-02  0:00 ` Robert Dewar
@ 1997-05-09  0:00   ` nickerson
  0 siblings, 0 replies; 7+ messages in thread
From: nickerson @ 1997-05-09  0:00 UTC (permalink / raw)




In article <dewar.862575815@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) 
writes:

|>The message seems clear enough "file can have only one compilation unit",
|>means that a single file can contain only one compilation unit, and the
|>file you submitted contains two. The Ada standard says nothing about files,
|>or how sources are arranged into files, so this is a place that Ada compilers
|>may differ (some Ada compilers do allow multiple units in a single file).
|>
|>Actually it is generally a bad idea to do what you did -- put the spec and
|>the body in the same unit, because that causes an unnecessary connection
|>between the two. The whole idea in Ada is to separate the spec and the
|>body, so putting them in separate files is recommended in any case.

it may "generally" be a bad idea, but "specifically" when one is 
trying something out or has existing code it is the "reasonable" 
thing to try; I quite identify with John - myself having used a 
compiler which did the "expected" thing and allowed multiple units 
per file;

--bn (Bart Nickerson)
nickerson@mirage.vms.boeing.com
(206) 662-0183




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada as 2nd Lang, p. 678
  1997-05-01  0:00 Ada as 2nd Lang, p. 678 John M. Greer
  1997-04-30  0:00 ` Matthew Heaney
  1997-05-02  0:00 ` Robert Dewar
@ 1997-05-12  0:00 ` Norman H. Cohen
  2 siblings, 0 replies; 7+ messages in thread
From: Norman H. Cohen @ 1997-05-12  0:00 UTC (permalink / raw)



John M. Greer wrote:
> 
> I was wondering if anyone could help for a second . . .
> Ada as a Second Language (My favorite book) 

Thank you.

> gives this listing
> for an example using Generic subprograms, but GNAT complains of end-of-line;
> it sees the declaration and stops.
> "end of file expected, file can have only one compilation unit
> gnatmake: "cyclic_successor_template.adb" compilation error"

See page 593, which says, "The GNU/NYU Ada Translator (GNAT) uses an
ordinary directory of Ada source files as an environment.  Each file
contains one compilation unit and has a file name that reflects the name
of the compilation unit.  (A file containing several compilation units
is passed through a program that chops it into smaller pieces, each
containing one compilation unit.)"

The chopping program is called gnatchop, and it is fully described in
the GNAT documentation.

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada as 2nd Lang, p. 678
@ 1997-05-12  0:00 Marin David Condic, 561.796.8997, M/S 731-93
  1997-05-13  0:00 ` Robert Dewar
  0 siblings, 1 reply; 7+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-93 @ 1997-05-12  0:00 UTC (permalink / raw)



nickerson@MIRAGE.VMS.BOEING.COM writes:
>it may "generally" be a bad idea, but "specifically" when one is
>trying something out or has existing code it is the "reasonable"
>thing to try; I quite identify with John - myself having used a
>compiler which did the "expected" thing and allowed multiple units
>per file;
>
    I have found that in circumstances where I want more than one
    compilation unit in the same file (say, because I'm doing
    quick-&-dirty concept testing or I'm e-mailing the implementation
    back & forth with another implementor) that I can get by just fine
    using gnatchop.

    Typically, I'll edit a file called <app-name>.chop, save the file,
    do a "gnatchop -w <app-name>.chop", followed by a "gnatmake
    main_unit". It works pretty well if I want the whole program in
    one file. (I haven't figured out how to get gnatchop to work in a
    .BAT file - my ignorance of MS-DOS no doubt. But that might
    provide a means of building a compilation procedure that separates
    out anything where you've combined spec/body for a specific
    reason.) I'll admit it's not the best of all possible worlds, but
    it does work and is not so inconvenient as to make it impossible
    to live with.

    MDC

Marin David Condic, Senior Computer Engineer    ATT:        561.796.8997
Pratt & Whitney, GESP                           Fax:        561.796.4669
West Palm Beach, FL                             Internet:   CONDICMA@PWFL.COM
===============================================================================
    "You see that ****ing fish? If he'd kept his mouth shut he
    wouldn'ta got caught."

        --  Sam Giancana, on a stuffed swordfish
===============================================================================




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada as 2nd Lang, p. 678
  1997-05-12  0:00 Marin David Condic, 561.796.8997, M/S 731-93
@ 1997-05-13  0:00 ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1997-05-13  0:00 UTC (permalink / raw)



Marin said

<<one file. (I haven't figured out how to get gnatchop to work in a
.BAT file - my ignorance of MS-DOS no doubt. But that might>>

Indeed, ignorance of MS-DOS :-)

In fact if you don't know how to do this, then you don't know how to
call any DOS .bat file from another .bat file, a pretty crippling
restriction.

The way to do it in DOS, (I think this was introduced in DOS 2.0, but
I don't have the energy to go rummage in my old DOS manuals) is

call gnatchop ....






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-05-13  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-01  0:00 Ada as 2nd Lang, p. 678 John M. Greer
1997-04-30  0:00 ` Matthew Heaney
1997-05-02  0:00 ` Robert Dewar
1997-05-09  0:00   ` nickerson
1997-05-12  0:00 ` Norman H. Cohen
  -- strict thread matches above, loose matches on Subject: below --
1997-05-12  0:00 Marin David Condic, 561.796.8997, M/S 731-93
1997-05-13  0:00 ` Robert Dewar

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