* First attribute on Enumerated types
@ 1999-02-23 0:00 David Starner
0 siblings, 0 replies; 5+ messages in thread
From: David Starner @ 1999-02-23 0:00 UTC (permalink / raw)
I'm trying to compile a program that refers to Color'First, and GNAT
gives an error that
tree.ads:12:91: prefix for "First" attribute must be array
According to the Ada book at hand, First is a valid attribute for
enumerated types. What am I doing wrong? How do I get the first item in
an enumerated list?
--
The irony is, there ARE drugs that ENHANCE it. This says something
profound about either science or medicine or people or muppets or all
four. - S. John Ross
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First attribute on Enumerated types
[not found] <001e01be5f9d$ebe4d7e0$5b824a0c@rogers>
@ 1999-02-23 0:00 ` David Starner
1999-02-24 0:00 ` Mark A Biggar
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Starner @ 1999-02-23 0:00 UTC (permalink / raw)
To: James S. Rogers
"James S. Rogers" wrote:
>
> David,
>
> I suspect that, in your case, Color is a variable, and not a subtype name.
> The 'First attribute works for an enumeration type, not a variable of an
> enumeration type.
>
> Jim Rogers
> Colorado Springs, Colorado
>
> -----Original Message-----
> From: David Starner <dstarner98@aasaa.ofe.org>>
> >I'm trying to compile a program that refers to Color'First, and GNAT
> >gives an error that
> >tree.ads:12:91: prefix for "First" attribute must be array
> >According to the Ada book at hand, First is a valid attribute for
> >enumerated types. What am I doing wrong? How do I get the first item in
> >an enumerated list?
Since I quickly composed the first message, here's the actual code.
Color is definitely a type. It should be enumerated - is there any
way to tell the compiler that? In retrospect, that's probably my error.
with Lists;
generic
type Node_type is private;
type Color is private;
package Tree is
type Tree is limited private;
type Node_Pointer is access Node_type;
type TreePointer is access Tree;
package Tree_List is new Lists(TreePointer, Natural);
procedure SetRoot(BaseTree: in out Tree; Item: in Node_Pointer;
NewColor: in Color := Color'First);
procedure AddChild(BaseTree: in out Tree; Child: in TreePointer);
procedure RemoveChild(BaseTree: in out Tree; Child: in integer);
-- procedure RemoveChild(BaseTree: in out Tree; Child: in out
Tree_List.Pointer);
function GetRootData (BaseTree: in Tree) return Node_type;
procedure SetColor (BaseTree: in out Tree; NewColor: in Color);
private
type Tree is
record
Data: Node_Pointer;
NodeColor: Color;
Children: Tree_List.List;
end record;
end Tree;
--
The irony is, there ARE drugs that ENHANCE it. This says something
profound about either science or medicine or people or muppets or all
four. - S. John Ross
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First attribute on Enumerated types
1999-02-23 0:00 ` David Starner
1999-02-24 0:00 ` Mark A Biggar
1999-02-24 0:00 ` John English
@ 1999-02-24 0:00 ` Matthew Heaney
2 siblings, 0 replies; 5+ messages in thread
From: Matthew Heaney @ 1999-02-24 0:00 UTC (permalink / raw)
David Starner <dstarner98@aasaa.ofe.org> writes:
> Since I quickly composed the first message, here's the actual code.
> Color is definitely a type. It should be enumerated - is there any
> way to tell the compiler that? In retrospect, that's probably my error.
>
> with Lists;
> generic
> type Node_type is private;
> type Color is private;
> package Tree is
Say this instead:
generic
type Node_type is private;
type Color is (<>);
package Tree is
Read the section of the RM (or your fav textbook) that describes
"generic formal types."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First attribute on Enumerated types
1999-02-23 0:00 ` David Starner
1999-02-24 0:00 ` Mark A Biggar
@ 1999-02-24 0:00 ` John English
1999-02-24 0:00 ` Matthew Heaney
2 siblings, 0 replies; 5+ messages in thread
From: John English @ 1999-02-24 0:00 UTC (permalink / raw)
David Starner wrote:
> type Color is private;
... but not necessarily an enumeration; it might be a record type, or a Float...
> procedure SetRoot(BaseTree: in out Tree; Item: in Node_Pointer;
> NewColor: in Color := Color'First);
... but private types (or the record types that might be used in an instantiation)
don't have a 'First attribute...
Try this:
type Color is (<>);
or this:
type Color is private;
Color_First : Color; -- supply your desired "first" value here and use
-- Color_First instead of Color'First
> The irony is, there ARE drugs that ENHANCE it. This says something
> profound about either science or medicine or people or muppets or all
> four. - S. John Ross
Enhance what??? (just curious...;-)
-----------------------------------------------------------------
John English | mailto:je@brighton.ac.uk
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
-----------------------------------------------------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First attribute on Enumerated types
1999-02-23 0:00 ` David Starner
@ 1999-02-24 0:00 ` Mark A Biggar
1999-02-24 0:00 ` John English
1999-02-24 0:00 ` Matthew Heaney
2 siblings, 0 replies; 5+ messages in thread
From: Mark A Biggar @ 1999-02-24 0:00 UTC (permalink / raw)
David Starner wrote:
> Since I quickly composed the first message, here's the actual code.
> Color is definitely a type. It should be enumerated - is there any
> way to tell the compiler that? In retrospect, that's probably my error.
>
> with Lists;
> generic
> type Node_type is private;
> type Color is private;
change this to:
type Color is (<>);
That will restrict Color to either an emumeration or an integer range. Now
if you write the body code so that it only uses 'first, 'last, 'succ, 'pred,
etc. it should work correctly given any discrete type.
--
Mark Biggar
mark.a.biggar@lmco.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1999-02-24 0:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-23 0:00 First attribute on Enumerated types David Starner
[not found] <001e01be5f9d$ebe4d7e0$5b824a0c@rogers>
1999-02-23 0:00 ` David Starner
1999-02-24 0:00 ` Mark A Biggar
1999-02-24 0:00 ` John English
1999-02-24 0:00 ` Matthew Heaney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox