comp.lang.ada
 help / color / mirror / Atom feed
* generic package, can't find an error
@ 2007-05-12 13:50 pilarp
  2007-05-12 13:56 ` pilarp
  2007-05-12 15:15 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 3+ messages in thread
From: pilarp @ 2007-05-12 13:50 UTC (permalink / raw)


I wrote a small program using a generic package, one of its functions
(the one posted below, named read_file_text) was supposed to get some
elements from a text file and write them on a standard output. In the
test program the package was instantiated with float type. The
remaining procedures and functions work properly, so I excluded them
from the source code of my program which you can see below. The source
code is included in 3 separate files: arrays.ads (package
specification), arrays.adb (package body) and test_arrays.adb (test
program using the package). While I compile arrays.ads and arrays.adb
succesfully, I get the following compiler error when I try to compile
test_arrays.adb:

"No visible program matches the specification for "Get" ". Please look
at the code and tell me what is wrong.

arrays.ads:

with Ada.Text_Io;
use ada.text_io;
generic
   type element is private;
   with procedure get(f:in file_type; o: out element) is <>;

   PACKAGE arrays IS
         TYPE arr IS ARRAY(Positive RANGE<>) OF element;
   FUNCTION Read_File_Text(File:IN String) RETURN arr;
END arrays;

arrays.adb:

package body arrays is
   FUNCTION Read_File_Text(File:IN String) RETURN arr IS
     F:File_Type; el:element; i:natural:=0;
   BEGIN
      BEGIN
         Open(F,In_File,File);
      EXCEPTION
         WHEN Name_Error=>
            DECLARE
               a:arr(1..0);
            BEGIN
               RETURN a;
            END;
         END;

      WHILE NOT (End_Of_File(F)) LOOP
            Get(F,el);
            skip_line(f);
         I:=I+1;
         END LOOP;
         reset(f,in_file);
      DECLARE
         a:arr(1..I);
      BEGIN
         FOR J IN 1..I LOOP
           get(f,a(i));
         END LOOP;
         Close(F);
         RETURN a;
      END;
   END read_file_Text;

test_arrays.adb:

with ada.text_io,ada.float_text_io,arrays;
use ada.text_io,ada.float_text_io;

procedure test_arrays is
   N:Natural; file:string(1..10):=(others=>' ');

 package arrays_float is new arrays(float,get);
   use arrays_float;

begin
put("Which file do you want to read?:");
   get_line(file,n);
   skip_line;
   for i in read_file_text(file)'range loop
      put(read_file_text(file)(i),0,2,0);
      put(" ");
   end loop;

end test_arrays;




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

* Re: generic package, can't find an error
  2007-05-12 13:50 generic package, can't find an error pilarp
@ 2007-05-12 13:56 ` pilarp
  2007-05-12 15:15 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 3+ messages in thread
From: pilarp @ 2007-05-12 13:56 UTC (permalink / raw)


I forgot to add "end arrays" at the end of arrays.adb in my first
post, but that's not a problem-it is included in my program.




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

* Re: generic package, can't find an error
  2007-05-12 13:50 generic package, can't find an error pilarp
  2007-05-12 13:56 ` pilarp
@ 2007-05-12 15:15 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry A. Kazakov @ 2007-05-12 15:15 UTC (permalink / raw)


On 12 May 2007 06:50:17 -0700, pilarp@poczta.onet.pl wrote:

> I wrote a small program using a generic package, one of its functions
> (the one posted below, named read_file_text) was supposed to get some
> elements from a text file and write them on a standard output. In the
> test program the package was instantiated with float type. The
> remaining procedures and functions work properly, so I excluded them
> from the source code of my program which you can see below. The source
> code is included in 3 separate files: arrays.ads (package
> specification), arrays.adb (package body) and test_arrays.adb (test
> program using the package). While I compile arrays.ads and arrays.adb
> succesfully, I get the following compiler error when I try to compile
> test_arrays.adb:
> 
> "No visible program matches the specification for "Get" ". Please look
> at the code and tell me what is wrong.
>
> arrays.ads:
> 
> with Ada.Text_Io;
> use ada.text_io;
> generic
>    type element is private;
>    with procedure get(f:in file_type; o: out element) is <>;

See the declaration of Get in Ada.Text_IO.Float_IO (of which instance
Ada.Float_Text_IO is). It is (RM A.10.9(7)):

 procedure Get(File : in File_Type; Item : out Num; Width : in Field := 0); 

So there is a third parameter you have to add to your formal procedure.

---------------
P.S. John P Woodruff did what you are probably looking for. See

http://www.dmitry-kazakov.de/ada/Numeric-Name-IO.htm

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

end of thread, other threads:[~2007-05-12 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-12 13:50 generic package, can't find an error pilarp
2007-05-12 13:56 ` pilarp
2007-05-12 15:15 ` Dmitry A. Kazakov

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