comp.lang.ada
 help / color / mirror / Atom feed
* gnatmake error I don't understand
@ 2014-04-04  0:35 agent
  2014-04-04  0:44 ` agent
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: agent @ 2014-04-04  0:35 UTC (permalink / raw)


I typed the following code from a recent issue of Linux Format

texthabits.ads
with Ada.Text_IO, Ada.Strings.Unbounded,
Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO;
use  Ada.Text_IO, Ada.Strings.Unbounded,
Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO;

-- REVISION HISTORY
-- ================
-- 31 Mar 14 -- Extracted from LinuxFormat LXF 181 coding article

Package texthabits is

PROCEDURE CreateOrOpen (File: in out File_Type; Name: in String; Form:
in String := "");

Procedure OpenOrCreateDataFile(File : in out File_Type; Name : in
String);

Procedure ReadAndDisplayDatafile(File : in out File_Type; Name :
String);

Procedure Habits ;

END texthabits;

-----------------------------------------------------------------------------------------
texthabits.adb
with Ada.Text_IO, Ada.Strings.Unbounded,
Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO, Ada.Calendar,
Ada.Directories;
use  Ada.Text_IO, Ada.Strings.Unbounded,
Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO, Ada.Calendar,
Ada.Directories;

-- REVISION HISTORY
-- ================
-- 31 Mar 14 -- Extracted from LinuxFormat LXF 181 coding article


Package body texthabits is
  habit : Unbounded_String;
  filehandle : File_Type;
  HabitFileName : String(1..13);
  ctr : Natural := 1;

PROCEDURE CreateOrOpen (File: in out File_Type; Name: in String; Form:
in String := "") is
BEGIN
  Open(File, Append_File, Name, Form);
EXCEPTION
  WHEN Ada.Text_IO.Name_Error =>
    Create(File, Out_File, Name, Form);  -- If must create file, then
append_file does not make sense, even if desired.
END CreateOrOpen;

Procedure OpenOrCreateDataFile(File : in out File_Type; Name : in
String) is
Begin
  Open(File, Append_File, Name);
Exception
  when Ada.Text_IO.Name_Error => Create(File => File, Mode =>
Append_File, Name => Name);
End OpenOrCreateDataFile;

Procedure ReadAndDisplayDatafile(File : in out File_Type; Name :
String) is
  buffer : String(1..100);
  length : Natural;
Begin
  IF EXISTS(Name) THEN
    Open(File => File, Mode => In_File, Name => Name);
    While not End_Of_File(File => File) loop
      Get_Line(File => File, item => buffer, last => Length);
      Put_Line(buffer(1..length));
    end loop;
    Close(File);
  END IF; -- if exists 
End ReadAndDisplayDatafile;


Procedure Habits is
Begin
  HabitFileName  :=  "habitfile.txt";
  ReadAndDisplayDatafile(filehandle, HabitFileName);  -- for input. Do
nothing if file does not exist.
  OpenOrCreateDataFile(filehandle, HabitFileName);    -- for output
  LOOP
    Put(" Enter a new habit, quit or exit: ");
    habit  :=  Get_Line;
    exit when (CAP(To_STRING(Head(Habit,4))) = "QUIT") OR
(CAP(to_string(Head(Habit,4))) = "EXIT") ;
    Put_Line(filehandle,Habit);
    ctr := ctr + 1;
  END LOOP;
  Close(filehandle);
  Put(" You entered and saved ");
  Put(ctr,3);
  Put_Line(" new habits.");
End Habits;

END texthabits;
---------------------------------------------------------------------------------
texthabits.gpr
project texthabits is
  for Source_Files use ("texthabits.adb", "texthabits.ads",
"tokenizea.ads", "tokenizea.adb");
  for Source_Dirs use (".", "./**");
  for Main use ("Habits");                                            

  package Builder is
    for Default_Switches ("Ada")
        use ("-g");
  end Builder;

  package Compiler is
    for Default_Switches ("Ada")
       use ("-fstack-check",
            "-gnatVa",
            "-g",
            "-gnato",
            "-gnatf",
            "-gnatwu",
            "-gnat2012");
  end Compiler;
   
end texthabits;

------------------------------------------------------------------------------
Ubuntu 12.04  amd64 version

gnatmake -Ptexthabits

gnatmake: "Habits" is not a source of project texthabits.

I don't understand the error or what to do about it.

Thanks,
Rob Solomon



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

* Re: gnatmake error I don't understand
  2014-04-04  0:35 gnatmake error I don't understand agent
@ 2014-04-04  0:44 ` agent
  2014-04-04  4:14 ` Per Sandberg
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 21+ messages in thread
From: agent @ 2014-04-04  0:44 UTC (permalink / raw)


I forgot 1 thing.  My tokenizea.adb routine has this line that I use
stolen from Modula-2:

function CAP(Item : Character) return Character renames
Ada.Characters.Handling.To_Upper;

function CAP(Item : String) return String renames
Ada.Characters.Handling.To_Upper;

So I with and use tokenizea because of the CAP function that I like
from Modula-2.

--rob solomon

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

* Re: gnatmake error I don't understand
  2014-04-04  0:35 gnatmake error I don't understand agent
  2014-04-04  0:44 ` agent
@ 2014-04-04  4:14 ` Per Sandberg
  2014-04-04  7:37   ` Simon Wright
  2014-04-04  7:50 ` Simon Wright
  2014-04-04 18:48 ` Stephen Leake
  3 siblings, 1 reply; 21+ messages in thread
From: Per Sandberg @ 2014-04-04  4:14 UTC (permalink / raw)


On Thu, 03 Apr 2014 20:35:18 -0400
agent@drrob1.com wrote:
The attribute "Main" is a file-name so it shall be:
   for main use ("habits.adb");
and not:
   for main use ("Habits");
/Per



> I typed the following code from a recent issue of Linux Format
> 
> texthabits.ads
> with Ada.Text_IO, Ada.Strings.Unbounded,
> Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO;
> use  Ada.Text_IO, Ada.Strings.Unbounded,
> Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO;
> 
> -- REVISION HISTORY
> -- ================
> -- 31 Mar 14 -- Extracted from LinuxFormat LXF 181 coding article
> 
> Package texthabits is
> 
> PROCEDURE CreateOrOpen (File: in out File_Type; Name: in String; Form:
> in String := "");
> 
> Procedure OpenOrCreateDataFile(File : in out File_Type; Name : in
> String);
> 
> Procedure ReadAndDisplayDatafile(File : in out File_Type; Name :
> String);
> 
> Procedure Habits ;
> 
> END texthabits;
> 
> -----------------------------------------------------------------------------------------
> texthabits.adb
> with Ada.Text_IO, Ada.Strings.Unbounded,
> Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO, Ada.Calendar,
> Ada.Directories;
> use  Ada.Text_IO, Ada.Strings.Unbounded,
> Ada.Strings.Unbounded.Text_IO, Ada.Integer_Text_IO, Ada.Calendar,
> Ada.Directories;
> 
> -- REVISION HISTORY
> -- ================
> -- 31 Mar 14 -- Extracted from LinuxFormat LXF 181 coding article
> 
> 
> Package body texthabits is
>   habit : Unbounded_String;
>   filehandle : File_Type;
>   HabitFileName : String(1..13);
>   ctr : Natural := 1;
> 
> PROCEDURE CreateOrOpen (File: in out File_Type; Name: in String; Form:
> in String := "") is
> BEGIN
>   Open(File, Append_File, Name, Form);
> EXCEPTION
>   WHEN Ada.Text_IO.Name_Error =>
>     Create(File, Out_File, Name, Form);  -- If must create file, then
> append_file does not make sense, even if desired.
> END CreateOrOpen;
> 
> Procedure OpenOrCreateDataFile(File : in out File_Type; Name : in
> String) is
> Begin
>   Open(File, Append_File, Name);
> Exception
>   when Ada.Text_IO.Name_Error => Create(File => File, Mode =>
> Append_File, Name => Name);
> End OpenOrCreateDataFile;
> 
> Procedure ReadAndDisplayDatafile(File : in out File_Type; Name :
> String) is
>   buffer : String(1..100);
>   length : Natural;
> Begin
>   IF EXISTS(Name) THEN
>     Open(File => File, Mode => In_File, Name => Name);
>     While not End_Of_File(File => File) loop
>       Get_Line(File => File, item => buffer, last => Length);
>       Put_Line(buffer(1..length));
>     end loop;
>     Close(File);
>   END IF; -- if exists 
> End ReadAndDisplayDatafile;
> 
> 
> Procedure Habits is
> Begin
>   HabitFileName  :=  "habitfile.txt";
>   ReadAndDisplayDatafile(filehandle, HabitFileName);  -- for input. Do
> nothing if file does not exist.
>   OpenOrCreateDataFile(filehandle, HabitFileName);    -- for output
>   LOOP
>     Put(" Enter a new habit, quit or exit: ");
>     habit  :=  Get_Line;
>     exit when (CAP(To_STRING(Head(Habit,4))) = "QUIT") OR
> (CAP(to_string(Head(Habit,4))) = "EXIT") ;
>     Put_Line(filehandle,Habit);
>     ctr := ctr + 1;
>   END LOOP;
>   Close(filehandle);
>   Put(" You entered and saved ");
>   Put(ctr,3);
>   Put_Line(" new habits.");
> End Habits;
> 
> END texthabits;
> ---------------------------------------------------------------------------------
> texthabits.gpr
> project texthabits is
>   for Source_Files use ("texthabits.adb", "texthabits.ads",
> "tokenizea.ads", "tokenizea.adb");
>   for Source_Dirs use (".", "./**");
>   for Main use ("Habits");                                            
> 
>   package Builder is
>     for Default_Switches ("Ada")
>         use ("-g");
>   end Builder;
> 
>   package Compiler is
>     for Default_Switches ("Ada")
>        use ("-fstack-check",
>             "-gnatVa",
>             "-g",
>             "-gnato",
>             "-gnatf",
>             "-gnatwu",
>             "-gnat2012");
>   end Compiler;
>    
> end texthabits;
> 
> ------------------------------------------------------------------------------
> Ubuntu 12.04  amd64 version
> 
> gnatmake -Ptexthabits
> 
> gnatmake: "Habits" is not a source of project texthabits.
> 
> I don't understand the error or what to do about it.
> 
> Thanks,
> Rob Solomon
> 


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

* Re: gnatmake error I don't understand
  2014-04-04  4:14 ` Per Sandberg
@ 2014-04-04  7:37   ` Simon Wright
  0 siblings, 0 replies; 21+ messages in thread
From: Simon Wright @ 2014-04-04  7:37 UTC (permalink / raw)


Per Sandberg <per.sandberg@sandat.dyndns.org> writes:

> The attribute "Main" is a file-name so it shall be:
>    for main use ("habits.adb");
> and not:
>    for main use ("Habits");

I know the manual[1] says it's a file name, but gnatmake & gprbuild will
assume ".adb" if the extension is omitted.

I think the problem is that it's being built on a Unix (case-sensitive)
file system; so

  for main use ("habits");

should work.

[1] http://docs.adacore.com/gprbuild-docs/html/gprbuild_ug.html#Main-Subprograms

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

* Re: gnatmake error I don't understand
  2014-04-04  0:35 gnatmake error I don't understand agent
  2014-04-04  0:44 ` agent
  2014-04-04  4:14 ` Per Sandberg
@ 2014-04-04  7:50 ` Simon Wright
  2014-04-04 13:35   ` Tero Koskinen
  2014-04-04 13:41   ` Robert A Duff
  2014-04-04 18:48 ` Stephen Leake
  3 siblings, 2 replies; 21+ messages in thread
From: Simon Wright @ 2014-04-04  7:50 UTC (permalink / raw)


agent@drrob1.com writes:

> Procedure Habits ;
>
> END texthabits;

(in GNAT) a main program needs to be at library level; you can't declare
Habits inside package Texthabits and use it as a main.

I'm glad to see LinuxFormat supporting Ada, though I have to say that at
a glance the coding style isn't what the community would recommend (eg,
CamelCase rather than Ada_Style). And the body doesn't need to re-with
packages withed by the spec.


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

* Re: gnatmake error I don't understand
  2014-04-04  7:50 ` Simon Wright
@ 2014-04-04 13:35   ` Tero Koskinen
  2014-04-04 13:41   ` Robert A Duff
  1 sibling, 0 replies; 21+ messages in thread
From: Tero Koskinen @ 2014-04-04 13:35 UTC (permalink / raw)


4.4.2014 10:50, Simon Wright wrote:
> agent@drrob1.com writes:
>
>> Procedure Habits ;
>>
>> END texthabits;
>
> (in GNAT) a main program needs to be at library level; you can't
> declare Habits inside package Texthabits and use it as a main.
>
> I'm glad to see LinuxFormat supporting Ada, though I have to say that
> at a glance the coding style isn't what the community would recommend
> (eg, CamelCase rather than Ada_Style). And the body doesn't need to
> re-with packages withed by the spec.
>

The above is agent@drrob1.com's own code. The LinuxFormat
Ada article by Juliet Kemp follows the recommended Ada_Style
(well, the printed version at least; I have the printed magazine
but I haven't checked does the electronic version of the code differ).

Yours,
  Tero

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

* Re: gnatmake error I don't understand
  2014-04-04  7:50 ` Simon Wright
  2014-04-04 13:35   ` Tero Koskinen
@ 2014-04-04 13:41   ` Robert A Duff
  2014-04-04 17:14     ` Simon Wright
  2014-04-04 21:27     ` Randy Brukardt
  1 sibling, 2 replies; 21+ messages in thread
From: Robert A Duff @ 2014-04-04 13:41 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> (in GNAT)

In Ada.

>... a main program needs to be at library level; you can't declare
> Habits inside package Texthabits and use it as a main.

It must be a library unit.  ("Library level" means something else.)
You can make it a child unit, though.

IMHO the language would be better without library subprograms.
The main procedure should be inside a package (but as you point
out, that's unfortunately illegal).

> I'm glad to see LinuxFormat supporting Ada, though I have to say that at
> a glance the coding style isn't what the community would recommend (eg,
> CamelCase rather than Ada_Style).

Agreed.

>...And the body doesn't need to re-with
> packages withed by the spec.

Yes.  Turn on a high level of warnings to catch mistakes
like that.

- Bob

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

* Re: gnatmake error I don't understand
  2014-04-04 13:41   ` Robert A Duff
@ 2014-04-04 17:14     ` Simon Wright
  2014-04-04 17:45       ` Adam Beneschan
  2014-04-05  0:35       ` Robert A Duff
  2014-04-04 21:27     ` Randy Brukardt
  1 sibling, 2 replies; 21+ messages in thread
From: Simon Wright @ 2014-04-04 17:14 UTC (permalink / raw)


Robert A Duff <bobduff@shell01.TheWorld.com> writes:

> Simon Wright <simon@pushface.org> writes:
>
>> (in GNAT)
>
> In Ada.
>
>>... a main program needs to be at library level; you can't declare
>> Habits inside package Texthabits and use it as a main.
>
> It must be a library unit.  ("Library level" means something else.)
> You can make it a child unit, though.

ARM 10.2(29)[1] says "An implementation may restrict the kinds of
subprograms it supports as main subprograms. However, an implementation
is required to support all main subprograms that are public
parameterless library procedures." so I think I was strictly right???
(apart from the "library level" confusion, sorry).

[1] http://www.adaic.org/resources/add_content/standards/12rm/html/RM-10-2.html#p29

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

* Re: gnatmake error I don't understand
  2014-04-04 17:14     ` Simon Wright
@ 2014-04-04 17:45       ` Adam Beneschan
  2014-04-05  0:35       ` Robert A Duff
  1 sibling, 0 replies; 21+ messages in thread
From: Adam Beneschan @ 2014-04-04 17:45 UTC (permalink / raw)


On Friday, April 4, 2014 10:14:21 AM UTC-7, Simon Wright wrote:
> Robert A Duff writes:
> 
> > Simon Wright writes:

> >> (in GNAT)

> > In Ada.

> ARM 10.2(29)[1] says "An implementation may restrict the kinds of
> subprograms it supports as main subprograms. However, an implementation
> is required to support all main subprograms that are public
> parameterless library procedures." so I think I was strictly right???
> (apart from the "library level" confusion, sorry).

I agree with you here; in Ada, it is legal to use a subprogram inside a package as the main subprogram, if the implementation supports it.  I don't know whether there are any implementations that do, however.  

(I do know of compilers that go beyond the "required to support" requirements in other ways, though.  Irvine Compiler's Ada compiler allows some library procedures with parameters to be used as main subprograms, as long as the parameters meet certain restrictions, and it uses the command-line arguments.)

                               -- Adam

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

* Re: gnatmake error I don't understand
  2014-04-04  0:35 gnatmake error I don't understand agent
                   ` (2 preceding siblings ...)
  2014-04-04  7:50 ` Simon Wright
@ 2014-04-04 18:48 ` Stephen Leake
  2014-04-04 19:25   ` Simon Wright
  3 siblings, 1 reply; 21+ messages in thread
From: Stephen Leake @ 2014-04-04 18:48 UTC (permalink / raw)


agent@drrob1.com writes:

> I typed the following code from a recent issue of Linux Format
>
<snip>

> texthabits.gpr
> project texthabits is
>   for Source_Files use ("texthabits.adb", "texthabits.ads",
> "tokenizea.ads", "tokenizea.adb");
>   for Source_Dirs use (".", "./**");
>   for Main use ("Habits");                                            

This says there is a file "habits.adb", but there isn't.

-- 
-- Stephe

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

* Re: gnatmake error I don't understand
  2014-04-04 18:48 ` Stephen Leake
@ 2014-04-04 19:25   ` Simon Wright
  2014-04-04 20:02     ` drrob106
  0 siblings, 1 reply; 21+ messages in thread
From: Simon Wright @ 2014-04-04 19:25 UTC (permalink / raw)


Stephen Leake <stephen_leake@stephe-leake.org> writes:

> agent@drrob1.com writes:
>
>> I typed the following code from a recent issue of Linux Format
>>
> <snip>
>
>> texthabits.gpr
>> project texthabits is
>>   for Source_Files use ("texthabits.adb", "texthabits.ads",
>> "tokenizea.ads", "tokenizea.adb");
>>   for Source_Dirs use (".", "./**");
>>   for Main use ("Habits");                                            
>
> This says there is a file "habits.adb", but there isn't.

Actually it says there is a file Habits.adb. Still not there!


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

* Re: gnatmake error I don't understand
  2014-04-04 19:25   ` Simon Wright
@ 2014-04-04 20:02     ` drrob106
  2014-04-04 20:43       ` Shark8
                         ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: drrob106 @ 2014-04-04 20:02 UTC (permalink / raw)


Some have already noticed my Modula-2 origins.  I am just learning Ada, so my coding style is that of what I know (as we all do).  I could not find electronic versions of that code, so I typed it myself using my own style.  

I was able to get this code to link by adding a separate procedure, testhabits.adb that merely called Habits from texthabits.

I was not aware that libraries listed in 'with' clause in a spec file do not need to be repeated in the body file.  I'll play with that a little.  I never coded this way in M-2, and I don't think that M-2 would have allowed that.

As was suggested, the error may be in my gpr file; the for Main use (""); line defines a separate file.

How would I write the gpr file if I were to try to have the main program in the package, as I've tried to do here?

It is my understanding that C-flavored languages do this routinely.  At least, from what I've seen in books and articles.

Thanks guys for all the help.


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

* Re: gnatmake error I don't understand
  2014-04-04 20:02     ` drrob106
@ 2014-04-04 20:43       ` Shark8
  2014-04-04 22:58         ` Jeffrey Carter
  2014-04-04 20:48       ` Simon Wright
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Shark8 @ 2014-04-04 20:43 UTC (permalink / raw)


On 04-Apr-14 14:02, drrob106@gmail.com wrote:
> How would I write the gpr file if I were to try to have the main program in the package,
> as I've tried to do here?

Hm, maybe a library-level rename? Something like:

ADS-File
-----------------------------------------
Procedure Main;

ADB-File
-----------------------------------------
with Parent;
Procedure Main renames Parent.Subprogram;

GPR-File
-----------------------------------------
-- ...
    for Main use ("ADB-File.adb");
-- ...

Sure the ADS-File may be extraneous, but won't hurt anything to my 
knowledge.


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

* Re: gnatmake error I don't understand
  2014-04-04 20:02     ` drrob106
  2014-04-04 20:43       ` Shark8
@ 2014-04-04 20:48       ` Simon Wright
  2014-04-05  0:33       ` Robert A Duff
  2014-04-05  8:17       ` Georg Bauhaus
  3 siblings, 0 replies; 21+ messages in thread
From: Simon Wright @ 2014-04-04 20:48 UTC (permalink / raw)


drrob106@gmail.com writes:

> How would I write the gpr file if I were to try to have the main
> program in the package, as I've tried to do here?

You wouldn't, because GNAT doesn't support that. You've hit on a
workable solution, though.

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

* Re: gnatmake error I don't understand
  2014-04-04 13:41   ` Robert A Duff
  2014-04-04 17:14     ` Simon Wright
@ 2014-04-04 21:27     ` Randy Brukardt
  1 sibling, 0 replies; 21+ messages in thread
From: Randy Brukardt @ 2014-04-04 21:27 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcclhvlmcu9.fsf@shell01.TheWorld.com...
...
> IMHO the language would be better without library subprograms.
> The main procedure should be inside a package (but as you point
> out, that's unfortunately illegal).

The very early versions of Janus/Ada required a package to be the main -- as 
there were no library-level subprograms at the time. But we just used the 
elaboration of that package to be a main -- we just force it to elaborate 
last; no way to use a subprogram inside of the package as a main (short of 
calling it in the begin part of the package). Janus/Ada still has an option 
to allow that sorrt of main (dunno if it actually works, I don't think 
anyone has used it for decades).

                                Randy.




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

* Re: gnatmake error I don't understand
  2014-04-04 20:43       ` Shark8
@ 2014-04-04 22:58         ` Jeffrey Carter
  0 siblings, 0 replies; 21+ messages in thread
From: Jeffrey Carter @ 2014-04-04 22:58 UTC (permalink / raw)


On 04/04/2014 01:43 PM, Shark8 wrote:
>
> ADS-File
> -----------------------------------------
> Procedure Main;
>
> ADB-File
> -----------------------------------------
> with Parent;
> Procedure Main renames Parent.Subprogram;
>
> GPR-File
> -----------------------------------------
> -- ...
>     for Main use ("ADB-File.adb");
> -- ...
>
> Sure the ADS-File may be extraneous, but won't hurt anything to my knowledge.

It might help. There's a little trick some colleagues played on people who left 
their workstations unlocked. Let us say Bob is working on a program called Alice 
and has the main subprogram in the file Alice.adb:

procedure Alice is ...
end Alice;

He has it to the point that he can run it, though some essential functionality 
is missing. We come along and create Foo.ads:

package Foo is
    pragma Elaborate_Body;

    exception Bar;
end Foo;

Foo.adb:

package body Foo is
    -- Nothum, eh?
begin -- Foo
    raise Bar;
end Foo;

and Alice.ads:

with Foo;
procedure Alice;

Now when he tests Alice, she raises Foo.Bar! People can spend a lot of time 
trying to figure that out.

-- 
Jeff Carter
"He didn't get that nose from playing ping-pong."
Never Give a Sucker an Even Break
110


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

* Re: gnatmake error I don't understand
  2014-04-04 20:02     ` drrob106
  2014-04-04 20:43       ` Shark8
  2014-04-04 20:48       ` Simon Wright
@ 2014-04-05  0:33       ` Robert A Duff
  2014-04-05  8:17       ` Georg Bauhaus
  3 siblings, 0 replies; 21+ messages in thread
From: Robert A Duff @ 2014-04-05  0:33 UTC (permalink / raw)


drrob106@gmail.com writes:

> I was able to get this code to link by adding a separate procedure,
> testhabits.adb that merely called Habits from texthabits.

Right.  To be portable, your 'main' must be a parameterless library
procedure (not nested in a package).

> I was not aware that libraries listed in 'with' clause in a spec file
> do not need to be repeated in the body file.  I'll play with that a
> little.  I never coded this way in M-2, and I don't think that M-2
> would have allowed that.

Are you sure?  It's been a long time since I used Modula-2, but
I seem to recall it behaved like Ada in this regard.

Enable warnings!  Otherwise, you will accumulate useless "with"
clauses as you modify your code (among other problems).

> How would I write the gpr file if I were to try to have the main
> program in the package, as I've tried to do here?

GNAT does not support that.  I don't think any Ada compilers support
that.

> It is my understanding that C-flavored languages do this routinely.

Well, C doesn't have packages.  The closest thing is "translation
unit", which is basically a .c source file, and you're right that
it can contain the "main" along with other stuff.

I think this area of Ada is slightly flawed.

> At least, from what I've seen in books and articles.

- Bob


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

* Re: gnatmake error I don't understand
  2014-04-04 17:14     ` Simon Wright
  2014-04-04 17:45       ` Adam Beneschan
@ 2014-04-05  0:35       ` Robert A Duff
  2014-04-05  0:52         ` Adam Beneschan
  1 sibling, 1 reply; 21+ messages in thread
From: Robert A Duff @ 2014-04-05  0:35 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Robert A Duff <bobduff@shell01.TheWorld.com> writes:
>
>> Simon Wright <simon@pushface.org> writes:
>>
>>> (in GNAT)
>>
>> In Ada.
>>
>>>... a main program needs to be at library level; you can't declare
>>> Habits inside package Texthabits and use it as a main.
>>
>> It must be a library unit.  ("Library level" means something else.)
>> You can make it a child unit, though.
>
> ARM 10.2(29)[1] says "An implementation may restrict the kinds of
> subprograms it supports as main subprograms. However, an implementation
> is required to support all main subprograms that are public
> parameterless library procedures." so I think I was strictly right???

Yes, you were right; I was wrong.  I wrote 10.2(7,29) for Ada 95,
and now that you've reminded me, I think I deliberately allowed
non-library-units (optionally supported).  That was a change from
Ada 83, as I recall.

So my "correction" of your "in GNAT" above to "In Ada" is not
a correct correction.  But it could be "in all known Ada compilers".

> (apart from the "library level" confusion, sorry).

Well, it doesn't make much sense for the 'main' to be non-library-level.

> [1] http://www.adaic.org/resources/add_content/standards/12rm/html/RM-10-2.html#p29

- Bob


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

* Re: gnatmake error I don't understand
  2014-04-05  0:35       ` Robert A Duff
@ 2014-04-05  0:52         ` Adam Beneschan
  0 siblings, 0 replies; 21+ messages in thread
From: Adam Beneschan @ 2014-04-05  0:52 UTC (permalink / raw)


On Friday, April 4, 2014 5:35:24 PM UTC-7, Robert A Duff wrote:

> Yes, you were right; I was wrong.  I wrote 10.2(7,29) for Ada 95,
> and now that you've reminded me, I think I deliberately allowed
> non-library-units (optionally supported).  That was a change from
> Ada 83, as I recall.

Yup.  RM83 10.1(8): "... every main program must be a subprogram that is a library unit."

                             -- Adam

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

* Re: gnatmake error I don't understand
  2014-04-04 20:02     ` drrob106
                         ` (2 preceding siblings ...)
  2014-04-05  0:33       ` Robert A Duff
@ 2014-04-05  8:17       ` Georg Bauhaus
  2014-04-05 13:28         ` Simon Wright
  3 siblings, 1 reply; 21+ messages in thread
From: Georg Bauhaus @ 2014-04-05  8:17 UTC (permalink / raw)


On 04/04/14 22:02, drrob106@gmail.com wrote:
> How would I write the gpr file if I were to try to have the main program in the package, as I've tried to do here?

Find switch -z in GNAT's documentation, e.g.

`-z'
      No main subprogram. Bind and link the program even if the unit name
      given on the command line is a package name. The resulting
      executable will execute the elaboration routines of the package
      and its closure, then the finalization routines.


You could call a subprogram from the package body's begin
block, or just treat the package body's begin block as a
procedure's body.



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

* Re: gnatmake error I don't understand
  2014-04-05  8:17       ` Georg Bauhaus
@ 2014-04-05 13:28         ` Simon Wright
  0 siblings, 0 replies; 21+ messages in thread
From: Simon Wright @ 2014-04-05 13:28 UTC (permalink / raw)


Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de> writes:

> On 04/04/14 22:02, drrob106@gmail.com wrote:
>> How would I write the gpr file if I were to try to have the main
>> program in the package, as I've tried to do here?
>
> Find switch -z in GNAT's documentation, e.g.
>
> `-z'
>      No main subprogram. Bind and link the program even if the unit name
>      given on the command line is a package name. The resulting
>      executable will execute the elaboration routines of the package
>      and its closure, then the finalization routines.
>
> You could call a subprogram from the package body's begin
> block, or just treat the package body's begin block as a
> procedure's body.

Indeed! Neat!

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

end of thread, other threads:[~2014-04-05 13:28 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-04  0:35 gnatmake error I don't understand agent
2014-04-04  0:44 ` agent
2014-04-04  4:14 ` Per Sandberg
2014-04-04  7:37   ` Simon Wright
2014-04-04  7:50 ` Simon Wright
2014-04-04 13:35   ` Tero Koskinen
2014-04-04 13:41   ` Robert A Duff
2014-04-04 17:14     ` Simon Wright
2014-04-04 17:45       ` Adam Beneschan
2014-04-05  0:35       ` Robert A Duff
2014-04-05  0:52         ` Adam Beneschan
2014-04-04 21:27     ` Randy Brukardt
2014-04-04 18:48 ` Stephen Leake
2014-04-04 19:25   ` Simon Wright
2014-04-04 20:02     ` drrob106
2014-04-04 20:43       ` Shark8
2014-04-04 22:58         ` Jeffrey Carter
2014-04-04 20:48       ` Simon Wright
2014-04-05  0:33       ` Robert A Duff
2014-04-05  8:17       ` Georg Bauhaus
2014-04-05 13:28         ` Simon Wright

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