comp.lang.ada
 help / color / mirror / Atom feed
* An improved Ada?
@ 2004-09-27 19:38 jn
  2004-09-27 20:40 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: jn @ 2004-09-27 19:38 UTC (permalink / raw)


Hi,

after spending numerous hours to do a simple double linked list
package - yes, I have seen charles - a 5 hours tedious car drive came
up with the following example of an improved Ada language:
  - prefix notation (as for tasks and protected types)
  - Ada OO syntax in line with tasks and protected objects
  - reference types 
  - controlled, allocates from Storage_Pools.Garbage_Collected :)
  - implicit up- and down-conversions

Here is my small example, based on the simset-library from Simula, not
complete but it should be easy for you to fill out the rest:)

package Simset is
   tagged type List_Type is private
   begin
      function First return Link_Type;
   end List_Type;

   tagged type Link_Type is private
   begin
      function Next return Link_Type;
   end Link_Type;
private
   tagged type Linkage_Type is
      Suc, Pred : Linkage;
   begin
      function Next return Linkage_Type;
      procedure Into (List : List_Type);
      procedure Initialize;
   end Linkage_Type;

   tagged type List_Type is new Linkage_Type with
   begin
      null;
   end List_Type;

   tagged type Link_Type is new Linkage_Type with
   begin
      null;
   end Link_Type;
end Simset;

package body Simset is
   tagged body Linkage_Type is
      function Next return Linkage_Type is
      begin
	if not Suc in List_Type then
           return Suc;
        else
           return null;
      end Suc;

      procedure Initialize is
      begin
         Suc  := This;
         Pred := This;
      end Initialize;
   end List_Type; 
 
   tagged body List_Type is
      function First return Link_Type is
      begin
	return Next;
      end First;
   end List_Type;
  
   tagged body Link_Type is
      function Next return Link_Type is
      begin
	return Linkage_Type(This).Next;
      end Suc;

      procedure Into (List : List_Type) is
      begin
          -- Unlink; -- remove from whichever list This is in
          -- manipulate pointers to put This last into List
      end Into;
   end List_Type;
end Simset;

-- Simset example usage

with Simset and use;
with Book_Intrinsics rename as BI;

procedure Example is
   tagged Book_Shelf is new List_Type;
   tagged Shopping_Cart is new List_Type;

   tagged Book_In_Shelf is new Link_Type with
      �uthor : BI.Author_Type;
      Title  : BI.Title_Type;
   end Book_In_Shelf;

   function Contains_Ada_In_Title (Title : BI.Title_Type) return
Boolean is
   begin ... end; 
   -- not part of example
   
   Shelf      : Book_Shelf := new Book_Shelf;
   Book, Buy  : Book_In_Shelf;
   Cart       : Shopping_Cart := new Shopping_Cart;
begin
   -- populate Shelf with books, not part of example

   Book := Shelf.First,
   while Book /= null loop
      if Ada_In_Title (Book.Title) then
         Buy := Book;
         Book := Book.Next
         Buy.Into (Cart);
      else
         Book := Book.Next;
      end if;
   end loop;
   -- pay for books in cart
end Example;



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

end of thread, other threads:[~2004-09-30 16:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-27 19:38 An improved Ada? jn
2004-09-27 20:40 ` Matthew Heaney
2004-09-28 20:41   ` Wojtek Narczynski
2004-09-28 22:54     ` Randy Brukardt
2004-09-28  5:45 ` Matthew Heaney
2004-09-29 17:05 ` jn
2004-09-29 18:26   ` Matthew Heaney
2004-09-29 21:33   ` Randy Brukardt
2004-09-29 22:15     ` tmoran
2004-09-30 16:55       ` tmoran

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