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

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