An array of records within an array of records (Still a problem) 
Author Message
 An array of records within an array of records (Still a problem)

I wonder if anyone could help me out, my problem is that I am trying to
create an array of records within an array of records representing CD
tracks within a CD, however I have tried every possible solution but the
error I receive most is "Sub-type mark required in this context", this
is on the line where I am specifying the ID of the CD to the array of
tracks.

my code is as follows:

Quote:
> type cd_track is
>         record
>                 title:string(1..20);
>                 artist:string(1..20);
>                 playlength:float:=0.00;
>                 id:integer;
>         end record;

> type cd_track_array is array(1..3) of cd_track;
> new_cd_track:cd_track_array;

> type cd is
>         record
>                 title:string(1..20);
>                 artist:string(1..20);
>                 id:new_cd_track;
>                 tracks:integer;
>         end record;

> type cd_array is array(1..3) of cd;
> new_cd_array:cd_array;

> begin

>                 new_cd_array(1):=("qqqqqqqqqqqqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",("qqqqqqqqqqqqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",0.34,1),3);
>                 put(new_cd_array(1).id(1).title);

  I am specifying the ID of the CD to the array of CD Tracks. I would of
thought it would work but as of yet it still wont. Although I have asked
this before the responses weren't really concerning the actual problem.

This is part of a larger coursework assignment this being a small
section, the course lecturer has had a look and cant figure it out yet,
could anyone have a look and tell me how I can incorporate an array of
records within an array of records and possibly fix this most annoying
error.

Any help greatly appreciated.

Thanks

(Using latest version of GNAT with TEXT_IO, with windows 95)



Wed, 18 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Hi,

The error message means exactly what it says: you need a subtype mark where
you had put the name of an object.

The following code shows how it's done.
Also, note that you must assign all three elements of the track array,
otherwise you will get an error at run time,

Further, the use of named association instead of positional association, and
the organized layout of the assignment statement will make the code easier
to understand and maintain.

Finally, since many news readers cannot display HTML, you should use plain
text when posting to widely-read newsgroups.

with Ada.Text_Io;procedure Mullen is   type Cd_Track is      record
Title:String(1..20);         Artist:String(1..20);
Playlength:Float:=0.00;         Id:Integer;      end record;   type
Cd_Track_Array is array(1..3) of Cd_Track;   -- New_Cd_Track:Cd_Track_Array;
type Cd is      record         Title:String(1..20);
Artist:String(1..20);         Id:Cd_Track_Array;         Tracks:Integer;
end record;   type Cd_Array is array(1..3) of Cd;
New_Cd_Array:Cd_Array;begin   New_Cd_Array (1) :=     (Title  =>
"aaaaaaaaaaaaaaaaaaaa",      Artist => "bbbbbbbbbbbbbbbbbbbb",      Id
=> (1 => (Title      => "cccccccccccccccccccc",                       Artist
=> "dddddddddddddddddddd",                       Playlength => 0.34,
Id         => 1),                 2 => (Title      =>
"eeeeeeeeeeeeeeeeeeee",                       Artist     =>
"ffffffffffffffffffff",                       Playlength => 0.35,
Id         => 2),                 3 => (Title      =>
"gggggggggggggggggggg",                       Artist     =>
"hhhhhhhhhhhhhhhhhhhh",                       Playlength => 0.36,
Id         => 3)                ),      Tracks => 3);   Ada.Text_Io.Put
(New_Cd_Array(1).Id(1).Title);end Mullen;

    I wonder if anyone could help me out, my problem is that I am trying to
create an array of records within an array of records representing CD tracks
within a CD, however I have tried every possible solution but the error I
receive most is "Sub-type mark required in this context", this is on the
line where I am specifying the ID of the CD to the array of tracks.
    my code is as follows:

type cd_track is
        record
                title:string(1..20);
                artist:string(1..20);
                playlength:float:=0.00;
                id:integer;
        end record;

type cd_track_array is array(1..3) of cd_track;
new_cd_track:cd_track_array;

type cd is
        record
                title:string(1..20);
                artist:string(1..20);
                id:new_cd_track;
                tracks:integer;
        end record;

type cd_array is array(1..3) of cd;
new_cd_array:cd_array;

begin

new_cd_array(1):=("qqqqqqqqqqqqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",("qqqqqqqqqq
qqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",0.34,1),3);
                put(new_cd_array(1).id(1).title);
      I am specifying the ID of the CD to the array of CD Tracks. I would of
thought it would work but as of yet it still wont. Although I have asked
this before the responses weren't really concerning the actual problem.
    This is part of a larger coursework assignment this being a small
section, the course lecturer has had a look and cant figure it out yet,
could anyone have a look and tell me how I can incorporate an array of
records within an array of records and possibly fix this most annoying
error.

    Any help greatly appreciated.

    Thanks

    (Using latest version of GNAT with TEXT_IO, with windows 95)



Wed, 18 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Quote:

>> type cd_track_array is array(1..3) of cd_track;
>> new_cd_track:cd_track_array;

>> type cd is
>>         record
>>                 title:string(1..20);
>>                 artist:string(1..20);
>>                 id:new_cd_track;
>>                 tracks:integer;
>>         end record;

>> type cd_array is array(1..3) of cd;
>> new_cd_array:cd_array;

>> begin
>>                 new_cd_array(1):=("qqqqqqqqqqqqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",("qqqqqqqqqqqqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",0.34,1),3);
>>                 put(new_cd_array(1).id(1).title);

>  I am specifying the ID of the CD to the array of CD Tracks. I would of
>thought it would work but as of yet it still wont. Although I have asked
>this before the responses weren't really concerning the actual problem.

Your assignment of one CD only contains data for one cd_track; the cd
record contains a new_cd_track (how, I'm not sure; I would expect
you'd have to use a type in the declaration, not a variable, but hey,
whatever works), and a new_cd_track is an array of 3 cd_tracks. So,
your assignment needs to be a bit uglier, along the lines of:
new_cd_array(1):=(title,artist,((cd_track1),(cd_track2),(cd_track3)),tracks);
Note the array aggregate containing the cd_track aggregates.

- Arthur
  (arthurw at bigfoot.com)



Wed, 18 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

R Mullen notes:

<<  I am specifying the ID of the CD to the array of CD Tracks. I would of
thought it would work but as of yet it still wont. Although I have asked
this before the responses weren't really concerning the actual problem.

How do you expect people to respond to "the actual problem" if you keep
secret what your problem is "it still won't (work)" is not exactly
a detailed problem report!

Actually the writer here is a student, who perhaps can be forgiven for
the vague report :-)

But I am constantly amazed by the reports we sometimes get from experienced
software engineers that are equally vague, and have phrases like
"doesn't work", "bombs" etc.

A good working rule whenever you ask anyone for help, either informally in
a context like this one, or when reporting a problem under a formal support
contract is:

(a) provide the entire code that shows the problem if you can, or
        preferably (if you can) a cut down example.

(b) say exactly what you saw, in its entirety

(c) say why you think this report is wrong, and what you expected to see.

Part (c) is very important. It is a common occurrence for people to
post code that behaves exactly as one would expect given a reasonable
knowledge of Ada, and the issue is understanding the (often very strange)
misconception(s) that lead to the question being asked in the first place.



Wed, 18 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Quote:
> type cd_track_array is array(1..3) of cd_track;
> new_cd_track:cd_track_array;
> ...
>                 id:new_cd_track;

You need          id:cd_track_array;
What you have now is like
  A : Integer;
  B : A;
It's a good idea to pay a lot of attention to naming.  'cd_track_array'
could be a particular array of cd_track's, or it could be, as it is
here, a type - a general description of any set of three cd_track's.
Some people like to put _type or _t or make a plural for a type name to
distinguish it from a variable name, or perhaps use _array for the type
and _list for the variable, or prefix the variable with The_ or A_, or
whatever.  It can be really helpful if you adopt some convention and
then stick to it.  And to the extent your programs are to be read by
others, it's good if you and they share the same conventions.
  Hoping this thread doesn't turn into another war over which
convention is 'right'.    Tom Moran


Wed, 18 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Note:  This same message was inadvertently sent earlier in Rich Text Format
(HTML).  Sorry about that.  Let's see if this is more readable.

Hi,

The error message means exactly what it says: you need a subtype mark where
you had put the name of an object.

The following code shows how it's done.
Also, note that you must assign all three elements of the track array,
otherwise you will get an error at run time,

Further, the use of named association instead of positional association, and
the organized layout of the assignment statement will make the code easier
to understand and maintain.

Finally, since many news readers cannot display HTML, you should use plain
text when posting to widely-read newsgroups.

with Ada.Text_Io;
procedure Mullen is
   type Cd_Track is
   record
      Title:String(1..20);
      Artist:String(1..20);
      Playlength:Float:=0.00;
      Id:Integer;
   end record;

   type Cd_Track_Array is array(1..3) of Cd_Track;
--   New_Cd_Track:Cd_Track_Array;

   type Cd is
   record
      Title:String(1..20);
      Artist:String(1..20);
      Id:Cd_Track_Array;
      Tracks:Integer;
   end record;

   type Cd_Array is array(1..3) of Cd;
   New_Cd_Array:Cd_Array;

begin

   New_Cd_Array (1) :=
      (Title => "aaaaaaaaaaaaaaaaaaaa",
      Artist => "bbbbbbbbbbbbbbbbbbbb",
      Id => ( 1=> (Title => "cccccccccccccccccccc",
            Artist => "dddddddddddddddddddd",
            Playlength => 0.34,
            Id => 1),
         2=> (Title => "eeeeeeeeeeeeeeeeeeee",
            Artist => "ffffffffffffffffffff",
            Playlength => 0.35,
            Id => 2),
         3=> (Title => "gggggggggggggggggggg",
            Artist => "hhhhhhhhhhhhhhhhhhhh",
            Playlength => 0.36,
            Id => 3)
         ),
      Tracks => 3);

   Ada.Text_Io.Put (New_Cd_Array(1).Id(1).Title);

end Mullen;


    I wonder if anyone could help me out, my problem is that I am trying to
create an array of records within an array of records representing CD tracks
within a CD, however I have tried every possible solution but the error I
receive most is "Sub-type mark required in this context", this is on the
line where I am specifying the ID of the CD to the array of tracks.
    my code is as follows:

type cd_track is
        record
                title:string(1..20);
                artist:string(1..20);
                playlength:float:=0.00;
                id:integer;
        end record;

type cd_track_array is array(1..3) of cd_track;
new_cd_track:cd_track_array;

type cd is
        record
                title:string(1..20);
                artist:string(1..20);
                id:new_cd_track;
                tracks:integer;
        end record;

type cd_array is array(1..3) of cd;
new_cd_array:cd_array;

begin

new_cd_array(1):=("qqqqqqqqqqqqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",("qqqqqqqqqq
qqqqqqqqqq","qqqqqqqqqqqqqqqqqqqq",0.34,1),3);
                put(new_cd_array(1).id(1).title);
      I am specifying the ID of the CD to the array of CD Tracks. I would of
thought it would work but as of yet it still wont. Although I have asked
this before the responses weren't really concerning the actual problem.
    This is part of a larger coursework assignment this being a small
section, the course lecturer has had a look and cant figure it out yet,
could anyone have a look and tell me how I can incorporate an array of
records within an array of records and possibly fix this most annoying
error.

    Any help greatly appreciated.

    Thanks

    (Using latest version of GNAT with TEXT_IO, with windows 95)



Wed, 18 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Your playlength should not be of type float.

Try a fixed type with range constraint.

Pascal.

--

--|------------------------------------------------------------
--| Pascal Obry                               Team-Ada Member |
--|                                                           |
--| EDF-DER-IPN-SID- Ingnierie des Systmes d'Informations   |
--|                                                           |

--| 1 Av Gnral de Gaulle  voice : +33-1-47.65.50.91         |
--| 92141 Clamart CEDEX     fax   : +33-1-47.65.50.07         |
--| FRANCE                                                    |
--|------------------------------------------------------------
--|
--|   http://ourworld.compuserve.com/homepages/pascal_obry
--|
--|   "The best way to travel is by means of imagination"



Fri, 20 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Quote:

> Some people like to put _type or _t or make a plural for a type name to
> distinguish it from a variable name, or perhaps use _array for the type
> and _list for the variable, or prefix the variable with The_ or A_, or
> whatever.  It can be really helpful if you adopt some convention and
> then stick to it.  And to the extent your programs are to be read by
> others, it's good if you and they share the same conventions.
>   Hoping this thread doesn't turn into another war over which
> convention is 'right'.    Tom Moran

  No war needed; _Type is right :)

Sorry, I couldn't resist. I use _Type, and I just spent the weekend reading
the Ada 95 Booch components, which don't. It was subtly frustrating. It
would be nice if we (the Ada community) could agree on a consensus for this
issue, as we seem to have on the Capitalization_Of_Multi_Word_Names issue.

Maybe if we complete the Ada 95 Booch components, or some equivalent,
widely-useful library, that could serve as a basis for consensus. Hmm, a
quick glance thru some of the GNAT run-time sources indicates they don't
use either _Type or plural for types. Looks like I may end up in the
minority :( .

-- Stephen Leake



Fri, 20 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Quote:

> Sorry, I couldn't resist. I use _Type, and I just spent the weekend
> reading the Ada 95 Booch components, which don't.  It was subtly
> frustrating.  It would be nice if we (the Ada community) could agree
> on a consensus for this issue, as we seem to have on the
> Capitalization_Of_Multi_Word_Names issue.

The rule I was taught is a very simple one.  You should name your
types and your variables so that an object declaration like

    Open_Goal_Set: Goal_Set;

can be read aloud as a TRUE and USEFUL sentence, pronouncing the
colon as "is a".  Hence
    Open_Goal_Set is a Goal_Set
works, but
    Open_Goal_Set is a Goal_Set_Type
doesn't work, and
    Open_Goal_Set is a Goal_Sets
_really_ grates.

Note that this _is_ consistent with the names of the Ada built in
types:
    Space: Character;
NOT
    Space: Character_Type;
or  Space: Characters;

Unlike capitalisation, where the case pattern was _defined_ not to
make any difference to the predefined things in the language, we
_can't_ _consistently_ switch to a *_Type or *s convention.



Sun, 22 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

Stephen said

<<> Sorry, I couldn't resist. I use _Type, and I just spent the weekend

Quote:
> reading the Ada 95 Booch components, which don't.  It was subtly
> frustrating.  It would be nice if we (the Ada community) could agree
> on a consensus for this issue, as we seem to have on the
> Capitalization_Of_Multi_Word_Names issue.

Uniformity might be desirable here, but clearly the rule cannot be
to add _Type to every type (a real noise generator in my opinion),
since clearly this is not the style of the existing language design,
which defines many types.

The style in the RM (which I assume you also find subtly frustating) is
to use nouns as type names, so that something "is a" String or Integer
or Unbounded_String or whatever. Of course there are some cases where
Type is used (File_Type), so I would gather that the consensus from
the RM is to use one of these two styles depending on what is clearer.
Sounds good to me! It's certainly the approach I use.

Of course you have to be tuned in to the criterion of how to make his
this choice. I guess I must be, because I find the RM quite clear and
not frustrating, and I like its decisions on when to use Type and
when not to!



Sun, 22 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)


Quote:
> The rule I was taught is a very simple one.  You should name your
> types and your variables so that an object declaration like

>     Open_Goal_Set: Goal_Set;

> can be read aloud as a TRUE and USEFUL sentence, pronouncing the
> colon as "is a".

If you end your type names with "_Type", the rule is simply to read the
colon as "is of" instead.  Constructs such as

   for Day in Weekday_Type

read more naturally using the _Type suffix.

--
Norman H. Cohen

http://www.research.ibm.com/people/n/ncohen



Sun, 22 Oct 2000 03:00:00 GMT  
 An array of records within an array of records (Still a problem)

   > ... the colon could be read as IS A
   > ... the colon could be read is IS OF

It is commendible that both of these philosophies are attempting
to read the computer statements as English sentences (or French
or Russian or Sanskrit) as well they should.

The readings of IS A and IS OF finally explain why people have
different opinions as to HOW to read them as sentences.

Of course the original and, IMO, the best philosophy is to read
the colon as IS OF TYPE, which leads types to be either plurals or
classlike words.

It is surprizing and very pleasing that most of those who disagree
with me have good reasons and a rational explanation for their opinions.

The reason I think the plurals is the best is that they ALSO read
as English sentences in array definitions, array declarations, and
other constructs in which computer science is derived from mathematical
set theory (only finitized in space and time dimensions). That is,
the computer has a finite amount of memory and a finite amount of time
to complete.



Tue, 24 Oct 2000 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. an array of records within an array of records

2. Problems using an array within another array

3. Add Child Record Within New Parent Record form.

4. Simulation problem with arrays of records

5. problem with constrained arrays in descritiate records w/ GNAT305

6. Problem with with Array of U8 to Array of Array of Boolean

7. Arrays within UDT Arrays - Uggh!

8. Inserting Arrays within an Array in Tcl...

9. Records with a record # of zero problem

10. Array Record Variables

11. Record Array

12. How to build an array of 700,000 records?

 

 
Powered by phpBB® Forum Software