comp.lang.ada
 help / color / mirror / Atom feed
* help: String Sets in ADA???
@ 1998-09-25  0:00 Arash Vahidi
  1998-09-25  0:00 ` Bob Fletcher
  1998-09-25  0:00 ` dennison
  0 siblings, 2 replies; 3+ messages in thread
From: Arash Vahidi @ 1998-09-25  0:00 UTC (permalink / 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;       

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




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

end of thread, other threads:[~1998-09-25  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-25  0:00 help: String Sets in ADA??? Arash Vahidi
1998-09-25  0:00 ` Bob Fletcher
1998-09-25  0:00 ` dennison

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