comp.lang.ada
 help / color / mirror / Atom feed
* Ada.Containers.Indefinite_Doubly_Linked_Lists
@ 2007-02-05 17:47 Carroll, Andrew
  2007-02-05 18:33 ` Ada.Containers.Indefinite_Doubly_Linked_Lists Jeffrey R. Carter
  2007-02-05 20:39 ` Ada.Containers.Indefinite_Doubly_Linked_Lists Niklas Holsti
  0 siblings, 2 replies; 3+ messages in thread
From: Carroll, Andrew @ 2007-02-05 17:47 UTC (permalink / raw)
  To: comp.lang.ada

I think then this is basically what I need to do (out of context and
there may be mistakes).

Type Attribute is record
	Name: String(50);
	Type: String(25);
	...
End record;

Package Attribute_List is new new
Ada.Containers.Indefinite_Doubly_Linked_Lists (Attribute);

Type Table is record
	Name: String(50);
	Attributes:  Attribute_List;
End record

Package Table_List is new Ada.Containers.Indefinite_Doubly_Linked_Lists
(Table);



I'm kind of lost though as to where these package declarations should
go.  Should they be like:

Package Table_List_Thingy is

	Type Attribute is record
		Name: String(50);
		Type: String(25);
		...
	End record;

	Package Attribute_List is new new
Ada.Containers.Indefinite_Doubly_Linked_Lists (Attribute);

	Type Table is record
		Name: String(50);
		Attributes:  Attribute_List;
	End record

	Package Table_List is new
Ada.Containers.Indefinite_Doubly_Linked_Lists (Table);

End Table_List_Thingy;


OR

Procedure RunMe(...) is 

	Type Attribute is record
		Name: String(50);
		Type: String(25);
		...
	End record;

	Package Attribute_List is new new
Ada.Containers.Indefinite_Doubly_Linked_Lists (Attribute);

	Type Table is record
		Name: String(50);
		Attributes:  Attribute_List;
	End record

	Package Table_List is new
Ada.Containers.Indefinite_Doubly_Linked_Lists (Table);

Begin
	...

End RunMe;

What are your suggestions?

Andrew



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

* Re: Ada.Containers.Indefinite_Doubly_Linked_Lists
  2007-02-05 17:47 Ada.Containers.Indefinite_Doubly_Linked_Lists Carroll, Andrew
@ 2007-02-05 18:33 ` Jeffrey R. Carter
  2007-02-05 20:39 ` Ada.Containers.Indefinite_Doubly_Linked_Lists Niklas Holsti
  1 sibling, 0 replies; 3+ messages in thread
From: Jeffrey R. Carter @ 2007-02-05 18:33 UTC (permalink / raw)


Carroll, Andrew wrote:
> 
> Type Attribute is record
> 	Name: String(50);
> 	Type: String(25);

Type, of course, is a reserved word. String is an unconstrained array 
type, and needs to be constrained by a range:

Name : String (1 .. 50);

Note that Name will always be 50 characters. If you want Names of 
varying lengths, Unbounded_String is probably the easiest way to go.

> I'm kind of lost though as to where these package declarations should
> go.  Should they be like:
> 
> Package Table_List_Thingy is
> 
> 	Type Attribute is record
> 		Name: String(50);
> 		Type: String(25);
> 		...
> 	End record;
> 
> 	Package Attribute_List is new new
> Ada.Containers.Indefinite_Doubly_Linked_Lists (Attribute);
> 
> OR
> 
> Procedure RunMe(...) is 
> 
> 	Type Attribute is record
> 		Name: String(50);
> 		Type: String(25);
> 		...
> 	End record;
> 
> 	Package Attribute_List is new new
> Ada.Containers.Indefinite_Doubly_Linked_Lists (Attribute);

Yes. Either will work. Which you should use depends on the problem and 
your design. (Here we encounter one of Ada's most valuable features: you 
have to think about design before you start coding.)

It doesn't look as if you need the indefinite version for either of your 
lists.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53



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

* Re: Ada.Containers.Indefinite_Doubly_Linked_Lists
  2007-02-05 17:47 Ada.Containers.Indefinite_Doubly_Linked_Lists Carroll, Andrew
  2007-02-05 18:33 ` Ada.Containers.Indefinite_Doubly_Linked_Lists Jeffrey R. Carter
@ 2007-02-05 20:39 ` Niklas Holsti
  1 sibling, 0 replies; 3+ messages in thread
From: Niklas Holsti @ 2007-02-05 20:39 UTC (permalink / raw)


Carroll, Andrew wrote:
> [ ... ]
> Package Attribute_List is new new
> Ada.Containers.Indefinite_Doubly_Linked_Lists (Attribute);
> 
> Type Table is record
> 	Name: String(50);
> 	Attributes:  Attribute_List;
                      ^^^^^^^^^^^^^^
Should be            Attribute_List.List;
because Attribute_List is a package that manages lists of Attributes, 
not a data type. The data type is Attribute_List.List.

> End record

> Package Table_List is new Ada.Containers.Indefinite_Doubly_Linked_Lists
> (Table);

I find it clearer to use names in plural form for packages that manage 
many objects of a given type. In this case I would use the name 
Attribute_Lists (not ..._List) for the package that manages lists of 
Attribute objects (each such list is an object of type 
Attribute_Lists.List). I would use the name Table_Lists for the package 
that manages lists of Table objects (each such list is an object of type 
Table_Lists.List).

The language-defined Ada packages use the same convention, for example 
Ada.Containers.Doubly_Linked_Lists (not ..._List). Of course you can use 
any names you like.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

end of thread, other threads:[~2007-02-05 20:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-05 17:47 Ada.Containers.Indefinite_Doubly_Linked_Lists Carroll, Andrew
2007-02-05 18:33 ` Ada.Containers.Indefinite_Doubly_Linked_Lists Jeffrey R. Carter
2007-02-05 20:39 ` Ada.Containers.Indefinite_Doubly_Linked_Lists Niklas Holsti

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