comp.lang.ada
 help / color / mirror / Atom feed
From: Arash Vahidi <vahidi@ios.chalmers.se>
Subject: help: String Sets in ADA???
Date: 1998/09/25
Date: 1998-09-25T00:00:00+00:00	[thread overview]
Message-ID: <360B9AFA.1F99D1CD@ios.chalmers.se> (raw)

Hi' everyone

I'm an Ada-newbie and have a newbie question for you older guys :
How do you write a String-Set in adda without knowing the range of used
strings??
Here is my code, but lloks like I get Cosntraint_Error as soon as I make
an assigment (see the code).
Can I use some kind of pointers here ?? If yes, how?? (I tried every
forms of "access" and "'address" combinations I could think of)

If you come up with somthing, please let me know (vahidi@cd.chalmers.se)

Thanks for any help
  /Arash



----------------------------------   
with Ada.Text_Io; use Ada.Text_Io;


package body String_Set is

   type Node;
   type Node_Pointer is access Node;
   
   -- subtype String_Pointer is String(1..1024);  
   -- type String_Pointer is new String(1..1024);
   
   type Node is record
      Object : String( 1..1024 );
      -- Object : String_Pointer;
      Next   : Node_Pointer;
   end record;              
         
   First : Node_Pointer;
   
   procedure Init is
   begin
      First := null;
   end;

      
   procedure Insert( Object : in String) is
      Tmp : Node_Pointer;
   begin
      if in_Set( Object) = true then
         return;
      end if;
      
      if First = null then
         First := new Node;
         -- First.Object := String_Pointer(Object);
         First.Object := object;
         First.Next := null;
      else
         Tmp := First;
         loop exit when Tmp.Next = null;
            Tmp := Tmp.Next;
         end loop;         
         Tmp.Next := new Node;
         Tmp := Tmp.Next;
         Tmp.Object := Object;
         Tmp.Next := null;         
      end if;               
   end;      
                  
         
   function Is_Empty return Boolean is
   begin
      return First = null;
   end;
      
   function In_Set(Object : in String) return Boolean is
      Tmp : Node_Pointer;
   begin   
      Tmp := First;
      loop exit when Tmp = null;         
         if Tmp.Object = Object then
            return True;
         end if;            
         Tmp := Tmp.Next;         
      end loop;                           
      return False;
   end;
   
end String_Set;       

----------------------------------




             reply	other threads:[~1998-09-25  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-25  0:00 Arash Vahidi [this message]
1998-09-25  0:00 ` help: String Sets in ADA??? Bob Fletcher
1998-09-25  0:00 ` dennison
replies disabled

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