comp.lang.ada
 help / color / mirror / Atom feed
* Problem with generic linked list package
@ 2014-07-28 13:26 Laurent
  2014-07-29  7:51 ` Jacob Sparre Andersen
  2014-07-29  8:27 ` Stephen Leake
  0 siblings, 2 replies; 28+ messages in thread
From: Laurent @ 2014-07-28 13:26 UTC (permalink / raw)


Hi

As an exercise from my favorite Ada book I have to modify the linked list package into a generic one. 
Not very complicated I got nearly everything done. 

Test program and generic linked list package: https://github.com/Chutulu/Chapter-15.git

The only problem I have is with the Display procedure.

The author gives the ads file the rest is left as exercise.

Just below he explains that the Display procedure needs to be adapted.

Subtype Name_Type is String (1..20);

procedure Display_String (Item : in Name_Type) is
   begin -- Display_String
      Ada.Text_IO.Put (Item => Item);
      Ada.Text_IO.New_Line;
   end Display_String;

and then use it to instantiate the generic list with it.

   package GL is new Linked_Lists_Generic (Element_Type    => Name_Type,
                                           Display_Element => Display_String );

If I need a list with Integers I only have to change the Display procedure and everything is fine. No need to modify the list package. 

I have put that into my test program and the instantiation works so far.

If I want to print the content of my list using simply Display_String (L1); it fails because the procedure expects a String and gets a list. That is clear.

If I use GL.Display_String (L1); I get an error that Display_string is not declared in GL. Clear too. 

(1)Now I just don't know how to get it to work. Comments are welcome.

(2)How would Display_String iterate over the whole list? The Display procedure given in the book for the linked list is a recursive version. I have changed it to an iterative version, I think it was even asked as an exercise too.

So the given Display_String wouldn't work and I need to use my own version and just adapt it?

Would be very happy if I get this package to work because it is needed for the next exercises.

Thanks

Laurent


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

end of thread, other threads:[~2014-08-11  7:56 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-28 13:26 Problem with generic linked list package Laurent
2014-07-29  7:51 ` Jacob Sparre Andersen
2014-07-29  8:12   ` Laurent
2014-07-29  8:27 ` Stephen Leake
2014-07-29 15:38   ` Laurent
2014-08-07 19:07     ` Laurent
2014-08-07 19:21       ` Adam Beneschan
2014-08-07 19:25         ` Adam Beneschan
2014-08-07 22:20           ` Laurent
2014-08-07 23:35             ` Adam Beneschan
2014-08-08  4:42               ` Laurent
2014-08-09 14:32                 ` Laurent
2014-08-09 14:58                   ` AdaMagica
2014-08-09 15:22                   ` Jeffrey Carter
2014-08-09 18:51                   ` Shark8
2014-08-09 21:53                     ` Laurent
2014-08-09 22:25                       ` Jeffrey Carter
2014-08-10  8:22                       ` Simon Wright
2014-08-10 10:45                         ` Simon Wright
2014-08-10 20:20                           ` Laurent
2014-08-10 21:57                             ` Simon Wright
2014-08-10 23:42                               ` Jeffrey Carter
2014-08-11  4:51                                 ` Laurent
2014-08-11  5:13                                   ` Jeffrey Carter
2014-08-11  7:56                                     ` Laurent
2014-08-07 20:37       ` Shark8
2014-08-07 22:30         ` Laurent
2014-08-07 23:22           ` Shark8

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