comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada.Containers.Doubly_Linked_Lists
       [not found] <mailman.67.1170570920.18371.comp.lang.ada@ada-france.org>
@ 2007-02-04  8:10 ` Niklas Holsti
  2007-02-04 21:05 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
  1 sibling, 0 replies; 15+ messages in thread
From: Niklas Holsti @ 2007-02-04  8:10 UTC (permalink / raw)


Carroll, Andrew wrote:
> Hello,
>  
> I would like to understand how to use the Ada.Containers.Doubly_Linked_Lists
> package.  After I with Ada.Containers.Doubly_Linked_Lists and then
> declare a variable x: Ada.Containers.Doubly_Linked_Lists.List I get
> the error:
>  
> invalid prefix in selected component "doubly_linked_lists".
>  
> So, what I'm saying here is that I have no clue how to use the
> Ada.Containers.Doubly_Linked_Lists package and I'm hoping that
> someone here can show me how to use it.

The packages in Ada.Containers are "generic" packages, so you first have 
to make an "instance" of Doubly_Linked_Lists before your program can 
declare list variables. When you make an instance, you specify which 
type of elements the list can hold (Element_Type) and how to compare two 
elements for equality (the "=" operator for Element_Type).

See http://en.wikibooks.org/wiki/Ada_Programming/Generics for 
explanation and examples of generic packages, and 
http://www.adaic.com/standards/05rat/html/Rat-8.html for specific advice 
on Ada.Containers.

For example, here is how to make a package that manages lists of Integers:

    with Ada.Containers.Doubly_Linked_Lists;
    ...

    package Integer_Lists is
       new Ada.Containers.Doubly_Linked_Lists (
          Element_Type => Integer);

(I did not give any actual for the formal "=" operator because it 
defaults to the predefined "=" for comparing Integers.)

And here is how to declare a variable that holds a list of Integers:

    Ints : Integer_Lists.List;

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



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

* Re: Ada.Containers.Doubly_Linked_Lists
       [not found] <mailman.67.1170570920.18371.comp.lang.ada@ada-france.org>
  2007-02-04  8:10 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
@ 2007-02-04 21:05 ` Jeffrey R. Carter
  1 sibling, 0 replies; 15+ messages in thread
From: Jeffrey R. Carter @ 2007-02-04 21:05 UTC (permalink / raw)


Carroll, Andrew wrote:
>  
> I would like to understand how to use the 
> Ada.Containers.Doubly_Linked_Lists  package.  After I with 
> Ada.Containers.Doubly_Linked_Lists and then declare a variable x: 
> Ada.Containers.Doubly_Linked_Lists.List I get the error:
>  
> invalid prefix in selected component "doubly_linked_lists".

Ada.Containers.Doubly_Linked_Lists is not a package. It's a generic. A 
generic is like a template; you use it to create things (in this case, 
packages); this is called instantiation:

package P is new Ada.Containers.Doubly_Linked_Lists
    (Element_Type => Whatever, "=" => Some_Function);

Now P is a package, and may be used as any other package:

V : P.List;

-- 
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python & the Holy Grail
07



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

* Re: Ada.Containers.Doubly_Linked_Lists
       [not found] <mailman.69.1170624131.18371.comp.lang.ada@ada-france.org>
@ 2007-02-04 21:35 ` Niklas Holsti
  2007-02-04 22:08   ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
  2007-02-05  4:03 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
  1 sibling, 1 reply; 15+ messages in thread
From: Niklas Holsti @ 2007-02-04 21:35 UTC (permalink / raw)


Carroll, Andrew wrote:
> Ahhhhh, I see.

(Please quote a bit of the post to which you are replying so that the 
context of your "Ahhhhh" is clearer :-)

> Okay, so, just out of curiosity, what do I do if I need the
> Node_type within Ada.Containers.Doubly_Linked_Lists to
> have an additional "attribute"? 

What Node_Type? Are you peeking at the *private* part of 
Ada.Containers.Doubly_Linked_Lists, or even at the source-code of the 
body of the generic? That's useless because you can't access the private 
stuff or the stuff in the body.

Whatever you want to keep in your list, put it in your Element_Type, the 
type that you use to instantiate Doubly_Linked_Lists. For example, make 
it a record type and put in whatever components you need.

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



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-04 21:35 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
@ 2007-02-04 22:08   ` Ludovic Brenta
  2007-02-05 15:43     ` Ada.Containers.Doubly_Linked_Lists Matthew Heaney
  0 siblings, 1 reply; 15+ messages in thread
From: Ludovic Brenta @ 2007-02-04 22:08 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@nospam.please> writes:

> Carroll, Andrew wrote:
>> Ahhhhh, I see.
>
> (Please quote a bit of the post to which you are replying so that the
> context of your "Ahhhhh" is clearer :-)
>
>> Okay, so, just out of curiosity, what do I do if I need the
>> Node_type within Ada.Containers.Doubly_Linked_Lists to
>> have an additional "attribute"?
>
> What Node_Type? Are you peeking at the *private* part of
> Ada.Containers.Doubly_Linked_Lists, or even at the source-code of the
> body of the generic? That's useless because you can't access the
> private stuff or the stuff in the body.
>
> Whatever you want to keep in your list, put it in your Element_Type,
> the type that you use to instantiate Doubly_Linked_Lists. For example,
> make it a record type and put in whatever components you need.

And, if Niklas' answer was unclear, do not add Prev or Next to your
Element_Type; it is the generic linked list's job to add and manage
them.  If all you want is an unbounded string, just say

package Lists_Of_Unbouned_Strings is
   new Ada.Containers.Doubly_Linked_Lists
     (Element_Type => Ada.Strings.Unbounded.Unbounded_Strings);

L : Lists_Of_Unbouned_Strings.List;

and off you go.

-- 
Ludovic Brenta.



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

* Re: Ada.Containers.Doubly_Linked_Lists
       [not found] <mailman.69.1170624131.18371.comp.lang.ada@ada-france.org>
  2007-02-04 21:35 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
@ 2007-02-05  4:03 ` Jeffrey R. Carter
  1 sibling, 0 replies; 15+ messages in thread
From: Jeffrey R. Carter @ 2007-02-05  4:03 UTC (permalink / raw)


Carroll, Andrew wrote:
>  
> Okay, so, just out of curiosity, what do I do if I need the Node_type 
> within Ada.Containers.Doubly_Linked_Lists to have an additional 
> "attribute"?  So instead of just having
>  
> type Node_Type is limited record
>  Element : Element_Access;
>  Next : Node_Access;
>  Prev : Node_Access;
> end record;

There is nothing named Node_Type in Ada.Containers.Doubly_Linked_Lists. 
See ARM-0X A.18.3 for the definition of this generic package:

http://www.adaic.org/standards/05rm/html/RM-A-18-3.html

An implementation may have something named Node_Type, but that would not 
be in the visible part of the specification, and so unavailable to you 
as a client of the generic or instantiations of it. Another 
implementation may be completely different, so relying on information 
about the implementation would be completely non-portable.

-- 
Jeff Carter
"Now go away or I shall taunt you a second time."
Monty Python & the Holy Grail
07



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-04 22:08   ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
@ 2007-02-05 15:43     ` Matthew Heaney
  0 siblings, 0 replies; 15+ messages in thread
From: Matthew Heaney @ 2007-02-05 15:43 UTC (permalink / raw)


On Feb 4, 5:08 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> If all you want is an unbounded string, just say
>
> package Lists_Of_Unbouned_Strings is
>    new Ada.Containers.Doubly_Linked_Lists
>      (Element_Type => Ada.Strings.Unbounded.Unbounded_Strings);
>
> L : Lists_Of_Unbouned_Strings.List;

A cleaner way to do this (that avoids having to use type
Unbounded_String) is:

package String_Lists is
  new Ada.Containers.Indefinite_Doubly_Linked_Lists (String);

procedure Op (L : String_Lists.List) is
begin
  L.Append ("Hello, World!");
end;




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

* Ada.Containers.Doubly_Linked_Lists
@ 2007-02-06 14:40 Carroll, Andrew
  0 siblings, 0 replies; 15+ messages in thread
From: Carroll, Andrew @ 2007-02-06 14:40 UTC (permalink / raw)
  To: comp.lang.ada


Thanks all!





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

* Re: Ada.Containers.Doubly_Linked_Lists
       [not found] <mailman.75.1170828524.18371.comp.lang.ada@ada-france.org>
@ 2007-02-07  7:16 ` Niklas Holsti
  2007-02-08 13:37 ` Ada.Containers.Doubly_Linked_Lists Stephen Leake
  1 sibling, 0 replies; 15+ messages in thread
From: Niklas Holsti @ 2007-02-07  7:16 UTC (permalink / raw)


Carroll, Andrew wrote:
> Okay, got the packages "instantiated" and all that and
> successfully appended an "element" to my list.

Good!

> How do I print the length to the console?

Assuming your list package is named Thing_Lists and your list object is 
named Things, of type Thing_Lists.List:

    Ada.Text_IO.Put_Line (
         "The length is"
       & Ada.Containers.Count_Type'Image (Thing_Lists.Length (Things)));

> Where is count_type defined?

In the package Ada.Containers.

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



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

* Ada.Containers.Doubly_Linked_Lists
@ 2007-02-07 14:52 Carroll, Andrew
  2007-02-07 15:06 ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
  2007-02-07 18:19 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
  0 siblings, 2 replies; 15+ messages in thread
From: Carroll, Andrew @ 2007-02-07 14:52 UTC (permalink / raw)
  To: comp.lang.ada

It's been over a year since I've even looked at an Ada program.  I
forgot pretty much everything.

I found a way to output the Count_Type that was different than your way
but I like yours.  I didn't realize that the 'Image "thing" applies to
all integer types.  What is the 'Image "thing" called again...?

Next question.  How do I output a tab character?
I don't see a constant for that in text_io.  


Andrew 



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-07 14:52 Ada.Containers.Doubly_Linked_Lists Carroll, Andrew
@ 2007-02-07 15:06 ` Ludovic Brenta
  2007-02-07 18:22   ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
  2007-02-07 18:19 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
  1 sibling, 1 reply; 15+ messages in thread
From: Ludovic Brenta @ 2007-02-07 15:06 UTC (permalink / raw)


Carroll, Andrew writes:
> It's been over a year since I've even looked at an Ada program.  I
> forgot pretty much everything.
>
> I found a way to output the Count_Type that was different than your way
> but I like yours.  I didn't realize that the 'Image "thing" applies to
> all integer types.  What is the 'Image "thing" called again...?

An attribute.

> Next question.  How do I output a tab character?
> I don't see a constant for that in text_io.  

Ada.Characters.Latin_1.HT (for Horizontal Tab).

-- 
Ludovic Brenta.



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-07 14:52 Ada.Containers.Doubly_Linked_Lists Carroll, Andrew
  2007-02-07 15:06 ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
@ 2007-02-07 18:19 ` Jeffrey R. Carter
  2007-02-08 10:44   ` Ada.Containers.Doubly_Linked_Lists Alex R. Mosteo
  1 sibling, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2007-02-07 18:19 UTC (permalink / raw)


Carroll, Andrew wrote:
> 
> I found a way to output the Count_Type that was different than your way
> but I like yours.  I didn't realize that the 'Image "thing" applies to
> all integer types.  What is the 'Image "thing" called again...?

The 'Image attribute is defined for all numeric types and all 
enumeration types.

-- 
Jeff Carter
"No one is to stone anyone until I blow this whistle,
do you understand? Even--and I want to make this
absolutely clear--even if they do say, 'Jehovah.'"
Monty Python's Life of Brian
74



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-07 15:06 ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
@ 2007-02-07 18:22   ` Jeffrey R. Carter
  2007-02-08 13:39     ` Ada.Containers.Doubly_Linked_Lists Stephen Leake
  0 siblings, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2007-02-07 18:22 UTC (permalink / raw)


Ludovic Brenta wrote:
> 
> Ada.Characters.Latin_1.HT (for Horizontal Tab).

Or Character'Val (9). Or Character'Succ (Ada.Characters.Latin_1.BS). But 
Latin_1 is the better way.

-- 
Jeff Carter
"No one is to stone anyone until I blow this whistle,
do you understand? Even--and I want to make this
absolutely clear--even if they do say, 'Jehovah.'"
Monty Python's Life of Brian
74



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-07 18:19 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
@ 2007-02-08 10:44   ` Alex R. Mosteo
  0 siblings, 0 replies; 15+ messages in thread
From: Alex R. Mosteo @ 2007-02-08 10:44 UTC (permalink / raw)


Jeffrey R. Carter wrote:

> Carroll, Andrew wrote:
>> 
>> I found a way to output the Count_Type that was different than your way
>> but I like yours.  I didn't realize that the 'Image "thing" applies to
>> all integer types.  What is the 'Image "thing" called again...?
> 
> The 'Image attribute is defined for all numeric types and all
> enumeration types.

Also check its 'Value companion... 




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

* Re: Ada.Containers.Doubly_Linked_Lists
       [not found] <mailman.75.1170828524.18371.comp.lang.ada@ada-france.org>
  2007-02-07  7:16 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
@ 2007-02-08 13:37 ` Stephen Leake
  1 sibling, 0 replies; 15+ messages in thread
From: Stephen Leake @ 2007-02-08 13:37 UTC (permalink / raw)


"Carroll, Andrew" <andrew.carroll@okstate.edu> writes:

> Okay, got the packages "instantiated" and all that and successfully
> appended an "element" to my list. How do I print the length to the
> console?
>  
> Where is count_type defined?

Your IDE should be able to tell you that, if the program is compiled.

In Emacs, put the cursor on the identifier "Count_Type", and hit C-c
C-d.

AdaGide can do the same thing, probably with some mouse click.

-- 
-- Stephe



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

* Re: Ada.Containers.Doubly_Linked_Lists
  2007-02-07 18:22   ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
@ 2007-02-08 13:39     ` Stephen Leake
  0 siblings, 0 replies; 15+ messages in thread
From: Stephen Leake @ 2007-02-08 13:39 UTC (permalink / raw)


"Jeffrey R. Carter" <jrcarter@acm.org> writes:

> Ludovic Brenta wrote:
>> Ada.Characters.Latin_1.HT (for Horizontal Tab).
>
> Or Character'Val (9). Or Character'Succ (Ada.Characters.Latin_1.BS).
> But Latin_1 is the better way.

Or ASCII.HT.

ASCII is labeled "Obsolete", but it will never go away; every Ada
compiler implements it. Maybe I'm just old-fashioned, but I prefer it
over Latin_1 for things like this :).

-- 
-- Stephe



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

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

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <mailman.69.1170624131.18371.comp.lang.ada@ada-france.org>
2007-02-04 21:35 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
2007-02-04 22:08   ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
2007-02-05 15:43     ` Ada.Containers.Doubly_Linked_Lists Matthew Heaney
2007-02-05  4:03 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
2007-02-07 14:52 Ada.Containers.Doubly_Linked_Lists Carroll, Andrew
2007-02-07 15:06 ` Ada.Containers.Doubly_Linked_Lists Ludovic Brenta
2007-02-07 18:22   ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
2007-02-08 13:39     ` Ada.Containers.Doubly_Linked_Lists Stephen Leake
2007-02-07 18:19 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter
2007-02-08 10:44   ` Ada.Containers.Doubly_Linked_Lists Alex R. Mosteo
     [not found] <mailman.75.1170828524.18371.comp.lang.ada@ada-france.org>
2007-02-07  7:16 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
2007-02-08 13:37 ` Ada.Containers.Doubly_Linked_Lists Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2007-02-06 14:40 Ada.Containers.Doubly_Linked_Lists Carroll, Andrew
     [not found] <mailman.67.1170570920.18371.comp.lang.ada@ada-france.org>
2007-02-04  8:10 ` Ada.Containers.Doubly_Linked_Lists Niklas Holsti
2007-02-04 21:05 ` Ada.Containers.Doubly_Linked_Lists Jeffrey R. Carter

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