* help: String Sets in ADA???
@ 1998-09-25 0:00 Arash Vahidi
1998-09-25 0:00 ` dennison
1998-09-25 0:00 ` Bob Fletcher
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
* Re: help: String Sets in ADA???
1998-09-25 0:00 help: String Sets in ADA??? Arash Vahidi
1998-09-25 0:00 ` dennison
@ 1998-09-25 0:00 ` Bob Fletcher
1 sibling, 0 replies; 3+ messages in thread
From: Bob Fletcher @ 1998-09-25 0:00 UTC (permalink / raw)
It might be worth having a look at the standard library package
Ada.Strings_Unbounded. This has an implementation of a string class that
can be of any length, and can dynamically change over its lifetime. I don't
know if there are any issues regarding run-time overheads when using it,
but I don't imagine there would be.
--
Bob Fletcher
Consultant, Logica UK
// All opinions are my own, not my employers'
Arash Vahidi <vahidi@ios.chalmers.se> wrote in article
<360B9AFA.1F99D1CD@ios.chalmers.se>...
> 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??
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: help: String Sets in ADA???
1998-09-25 0:00 help: String Sets in ADA??? Arash Vahidi
@ 1998-09-25 0:00 ` dennison
1998-09-25 0:00 ` Bob Fletcher
1 sibling, 0 replies; 3+ messages in thread
From: dennison @ 1998-09-25 0:00 UTC (permalink / raw)
In article <360B9AFA.1F99D1CD@ios.chalmers.se>,
Arash Vahidi <vahidi@ios.chalmers.se> wrote:
Having troube with our homework, are we? :-)
> Here is my code, but lloks like I get Cosntraint_Error as soon as I make
> an assigment (see the code).
...
> type Node is record
> Object : String( 1..1024 );
> -- Object : String_Pointer;
> Next : Node_Pointer;
> end record;
...
> procedure Insert( Object : in String) is
> Tmp : Node_Pointer;
> begin
...
> First.Object := object;
This line ^^^^^^^^^^^^^^^^^^^^^^^ will raise a constraint error if the string
passed in to Insert isn't *exactly* 1024 characters long. You could change it
to:
First.Object(1..Object'length) := Object;
If you want the rest of the string blanked out, you could add another line:
First.Object (Object'length + 1..First.Object'last) := (others => ' ');
The problem with all this is that after the call you don't have any way of
finding out how many characters in a node's object contain valid data. I'd
suggest looking into using the type Ada.Strings.Unbounded.Unbounded_String
instead of String(1..1024).
--
T.E.D.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
^ 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 ` dennison
1998-09-25 0:00 ` Bob Fletcher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox