comp.lang.ada
 help / color / mirror / Atom feed
* Charles container library usage examples
@ 2005-09-03  2:38 David Trudgett
  2005-09-03  5:15 ` Matthew Heaney
  0 siblings, 1 reply; 29+ messages in thread
From: David Trudgett @ 2005-09-03  2:38 UTC (permalink / raw)


Does anyone know where I can find some usage examples for the Charles
container library, or some code that makes use of Charles? 

I've got Charles downloaded and installed on my include path, but as a
newcomer to Ada, I'm having difficulty working out how it is intended
to be used.

The first thing I had in mind to do was to create a simple map, for
example, to translate the following Common Lisp:

(defvar *side-corners*
  '((2 (1 3))
    (4 (1 7))
    (6 (3 9))
    (8 (7 9))))

This is just a simple mapping of four particular integers (2, 4, 6, 8)
to four particular lists each consisting of two integers.

I use it in a function like this:

(defun side-corners (side)
  "Return a list of the (two) corners that flank the given side"
  (second (assoc side *side-corners*)))

so that the function call

(side-corners 2)

returns the list (1 3)


Any pointers to code samples, or other hints would be greatly
appreciated!

Thanks,

David



-- 

David Trudgett
http://www.zeta.org.au/~wpower/

Omnis enim res, quae dando non deficit, dum habetur
     et non datur, nondum habetur, quomodo habenda est.

For if a thing is not diminished by being shared with others,
     it is not rightly owned if it is only owned and not shared.

Book I, Chapter 1 "De doctrina christiana"
"Corpus Christianorum", "Series latina", Vol. 32, p. 6, lines 10-11.
Written 397 AD by Saint Augustinus




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

* Re: Charles container library usage examples
  2005-09-03  2:38 Charles container library usage examples David Trudgett
@ 2005-09-03  5:15 ` Matthew Heaney
  2005-09-03  9:45   ` Simon Wright
  2005-09-04  0:26   ` David Trudgett
  0 siblings, 2 replies; 29+ messages in thread
From: Matthew Heaney @ 2005-09-03  5:15 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

> Does anyone know where I can find some usage examples for the Charles
> container library, or some code that makes use of Charles?

Here's my Ada-Europe 2004 tutorial:

http://charles.tigris.org/charles_tutorial.ppt
http://charles.tigris.org/charles_tutorial.pdf

My original AI-302 proposal was based on Charles, and contains many
examples:

http://home.earthlink.net/~matthewjheaney/charles/ai302.txt


> I've got Charles downloaded and installed on my include path, but as a
> newcomer to Ada, I'm having difficulty working out how it is intended
> to be used.

Charles is more or less a port of the STL to Ada95, so if you can follow
an STL tutorial (there are lots of them on the web), then you shouldn't
have any problem extrapolating that to Charles.

The standard container library has changed significantly from my
original proposal, but even so you should be able to follow the AI-302
examples:

http://charles.tigris.org/source/browse/charles/src/ai302/examples/


> The first thing I had in mind to do was to create a simple map, for
> example, to translate the following Common Lisp:
> 
> (defvar *side-corners*
>   '((2 (1 3))
>     (4 (1 7))
>     (6 (3 9))
>     (8 (7 9))))

You can use a map, instantiated with type Integer as the key and an
instantiation of a list as the element.  Either the hashed map or the
ordered map would suffice.


> This is just a simple mapping of four particular integers (2, 4, 6, 8)
> to four particular lists each consisting of two integers.
> 
> I use it in a function like this:
> 
> (defun side-corners (side)
>   "Return a list of the (two) corners that flank the given side"
>   (second (assoc side *side-corners*)))
> 
> so that the function call
> 
> (side-corners 2)
> 
> returns the list (1 3)

Something like (I have omitted a few steps):

procedure Op (Map : Container_Type) is
   I : constant Iterator_Type := Find (Map, Key => 2);
   L : List_Types.Container_Type renames To_Access (I).all;
begin
   ...
end;

This is similar to the C++ code:

void f(const map_t& m)
{
   const map_t::const_iterator i = m.find (2);
   const list_t& L = *i;
   //...
}


> Any pointers to code samples, or other hints would be greatly
> appreciated!

Send me email (or continue posting to CLA) if you need any help.

-Matt



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

* Re: Charles container library usage examples
  2005-09-03  5:15 ` Matthew Heaney
@ 2005-09-03  9:45   ` Simon Wright
  2005-09-04  6:25     ` David Trudgett
  2005-09-04  0:26   ` David Trudgett
  1 sibling, 1 reply; 29+ messages in thread
From: Simon Wright @ 2005-09-03  9:45 UTC (permalink / raw)


Matthew Heaney <matthewjheaney@earthlink.net> writes:

> David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

>> The first thing I had in mind to do was to create a simple map, for
>> example, to translate the following Common Lisp:
>> 
>> (defvar *side-corners*
>>   '((2 (1 3))
>>     (4 (1 7))
>>     (6 (3 9))
>>     (8 (7 9))))
>
> You can use a map, instantiated with type Integer as the key and an
> instantiation of a list as the element.  Either the hashed map or the
> ordered map would suffice.

I would have used (for example)

  type Axis is (X, Y);
  type Coordinate is range 1 .. 8;
  type Position is array (Axis) of Coordinate;

as the element type (making some assumptions about the problem!). No
need to have a list as the element if the problem doesn't call for it
(though good to be able to if needed, of course).



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

* Re: Charles container library usage examples
  2005-09-03  5:15 ` Matthew Heaney
  2005-09-03  9:45   ` Simon Wright
@ 2005-09-04  0:26   ` David Trudgett
  2005-09-04  9:49     ` Matthew Heaney
  2005-09-04 17:19     ` Ludovic Brenta
  1 sibling, 2 replies; 29+ messages in thread
From: David Trudgett @ 2005-09-04  0:26 UTC (permalink / raw)


Hi Matthew,

Thanks for your quick reply to my query!


Matthew Heaney <matthewjheaney@earthlink.net> writes:

> David Trudgett <wpower@zeta.org.au.nospamplease>  writes:
>
>> Does anyone know where I can find some usage examples for the Charles
>> container library, or some code that makes use of Charles?
>
> Here's my Ada-Europe 2004 tutorial:
>
> http://charles.tigris.org/charles_tutorial.ppt
> http://charles.tigris.org/charles_tutorial.pdf

Yes, I've actually had a look through this slide show, but for me it's
usefulness was limited by not having the verbal explanations that go
with it! :-) Also, I couldn't find any complete example that includes
all the declarations etc. that one needs to get it working.


>
> My original AI-302 proposal was based on Charles, and contains many
> examples:
>
> http://home.earthlink.net/~matthewjheaney/charles/ai302.txt

Yes, a lot of work went into that (extremely long!) text file, and
there are no doubt some useful snippets in there, but once again it
omits the entire infrastructure that one needs to get something to
work (no doubt because it's considered elementary -- except it's not
to me! :-)).


>
>
>> I've got Charles downloaded and installed on my include path, but as a
>> newcomer to Ada, I'm having difficulty working out how it is intended
>> to be used.
>
> Charles is more or less a port of the STL to Ada95, so if you can follow
> an STL tutorial (there are lots of them on the web), then you shouldn't
> have any problem extrapolating that to Charles.

It's a possibility, but I have no familiarity with C++, and I'm only
getting started in Ada, so I think it will be more difficult than you
suggest.


>
> The standard container library has changed significantly from my
> original proposal, but even so you should be able to follow the AI-302
> examples:
>
> http://charles.tigris.org/source/browse/charles/src/ai302/examples/

These may prove to be useful, too, and I have had a look through the
hash map related ones. I think I made a bit of progress using these,
but they leave me guessing a bit what to "with" and "use", and where.

It's seeming to me at the moment that to make a simple data structure
consisting of a hash table of lists, I need to instantiate two generic
packages (requiring two separate files in GNAT, I assume), work out
the necessary WITH and USE clauses, figure out how to declare the
containers, and then put the code in to extract the data from the map
(for which you've given me a useful hint below, in "PROCEDURE OP").

Of course, in this case, I could certainly use an Ada array instead of
the list; and, in fact, I could also use an array instead of a
map. But I didn't think it was going to be hard to create and use a
map and list in Ada! :-) I'm hoping that it's looking harder than it
really is at the moment, simply because I'm not very conversant with
Ada generics yet.



>
>
>> The first thing I had in mind to do was to create a simple map, for
>> example, to translate the following Common Lisp:
>> 
>> (defvar *side-corners*
>>   '((2 (1 3))
>>     (4 (1 7))
>>     (6 (3 9))
>>     (8 (7 9))))
>
> You can use a map, instantiated with type Integer as the key and an
> instantiation of a list as the element.  Either the hashed map or the
> ordered map would suffice.

When I tried to instantiate a hashed map, it seemed to want me to
supply a hash function.


>
>
>> This is just a simple mapping of four particular integers (2, 4, 6, 8)
>> to four particular lists each consisting of two integers.
>> 
>> I use it in a function like this:
>> 
>> (defun side-corners (side)
>>   "Return a list of the (two) corners that flank the given side"
>>   (second (assoc side *side-corners*)))
>> 
>> so that the function call
>> 
>> (side-corners 2)
>> 
>> returns the list (1 3)
>
> Something like (I have omitted a few steps):
>
> procedure Op (Map : Container_Type) is
>    I : constant Iterator_Type := Find (Map, Key => 2);
>    L : List_Types.Container_Type renames To_Access (I).all;
> begin
>    ...
> end;

OK, thanks for that. That second line ("L :") is particularly useful.


>
> This is similar to the C++ code:
>
> void f(const map_t& m)
> {
>    const map_t::const_iterator i = m.find (2);
>    const list_t& L = *i;
>    //...
> }

Unfortunately, I'm unfamiliar with the STL. :-( But I can see the
similarity.


>
>
>> Any pointers to code samples, or other hints would be greatly
>> appreciated!
>
> Send me email (or continue posting to CLA) if you need any help.

I'll use the list for now, assuming that others might benefit besides
myself. Thanks.

David



-- 

David Trudgett
http://www.zeta.org.au/~wpower/

Naturally the common people don't want war...but after all it is the
leaders of a country who determine policy, and it is always a simple
matter to drag the people along....  All you have to do is tell them
they are being attacked, and denounce the pacifists for lack of
patriotism and exposing the country to danger.  It works the same in
any country.

    -- Hermann Goering (1893-1946), 1936




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

* Re: Charles container library usage examples
  2005-09-03  9:45   ` Simon Wright
@ 2005-09-04  6:25     ` David Trudgett
  2005-09-05 11:28       ` Georg Bauhaus
  0 siblings, 1 reply; 29+ messages in thread
From: David Trudgett @ 2005-09-04  6:25 UTC (permalink / raw)



Hi Simon,

Simon Wright <simon@pushface.org> writes:

> Matthew Heaney <matthewjheaney@earthlink.net> writes:
>
>> David Trudgett <wpower@zeta.org.au.nospamplease>  writes:
>
>>> The first thing I had in mind to do was to create a simple map, for
>>> example, to translate the following Common Lisp:
>>> 
>>> (defvar *side-corners*
>>>   '((2 (1 3))
>>>     (4 (1 7))
>>>     (6 (3 9))
>>>     (8 (7 9))))
>>
>> You can use a map, instantiated with type Integer as the key and an
>> instantiation of a list as the element.  Either the hashed map or the
>> ordered map would suffice.
>
> I would have used (for example)
>
>   type Axis is (X, Y);
>   type Coordinate is range 1 .. 8;
>   type Position is array (Axis) of Coordinate;
>

> as the element type (making some assumptions about the problem!). 

They do look like coordinates, don't they? :-) Does the following shed
any light?


   procedure Print_Board_Key is
   begin

      New_Line;
      Put("The board squares are numbered as follows:");
      New_Line(2);
      Put("  1 | 2 | 3 "); New_Line;
      Put(" -----------"); New_Line;
      Put("  4 | 5 | 6 "); New_Line;
      Put(" -----------"); New_Line;
      Put("  7 | 8 | 9 "); New_Line(2);

   end Print_Board_Key;


It's a simple tic tac toe game I'm playing around with to learn
Ada. I'm planning to put a GUI onto it before I'm finished with it!


> No need to have a list as the element if the problem doesn't call
> for it (though good to be able to if needed, of course).

It's a learning exercise, so doing things the hard way is not a
problem! :-) I'm just a bit surprised that adding a map and a list to
a program is turning into a major undertaking. I'm sure I'll get
there, though. I might have to do some more study on generics, though
I was hoping to be able to just *use* a map without having to have
detailed knowledge of how generics work.

Cheers,

David


-- 

David Trudgett
http://www.zeta.org.au/~wpower/

No great cause is ever won or lost. The battle must always be renewed
and the creed restated... For some things are universal, catholic and
undying... These do not age or pass out of fashion, for they symbolize
eternal things. They are the guardians of the freedom of the human
spirit, the proof of what our mortal frailty can achieve.

    -- John Buchan, biographer of Montrose




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

* Re: Charles container library usage examples
  2005-09-04  0:26   ` David Trudgett
@ 2005-09-04  9:49     ` Matthew Heaney
  2005-09-06  3:01       ` David Trudgett
  2005-09-04 17:19     ` Ludovic Brenta
  1 sibling, 1 reply; 29+ messages in thread
From: Matthew Heaney @ 2005-09-04  9:49 UTC (permalink / raw)



David Trudgett wrote:
>
> It's seeming to me at the moment that to make a simple data structure
> consisting of a hash table of lists, I need to instantiate two generic
> packages (requiring two separate files in GNAT, I assume), work out
> the necessary WITH and USE clauses, figure out how to declare the
> containers, and then put the code in to extract the data from the map
> (for which you've given me a useful hint below, in "PROCEDURE OP").

Yes, you need to make two instantiations: one to create a list of
integers, and another to create a map of lists.

If your list always comprises two elements, then you can use a
constrained array instead.  Something like:

  type Integer_Array is array (Positive range <>) of Integer;
  subtype Integer_Array_Subtype is Integer_Array (1 .. 2);

or the simpler:

   type Integer_Array is (1 .. 2) of Integer;

Then you can use that as the generic actual Element_Type in the
instantiation of the map (and hence get rid of the list instantiation
entirely).


> Of course, in this case, I could certainly use an Ada array instead of
> the list; and, in fact, I could also use an array instead of a
> map.

Yes, that's correct.


> But I didn't think it was going to be hard to create and use a
> map and list in Ada! :-) I'm hoping that it's looking harder than it
> really is at the moment, simply because I'm not very conversant with
> Ada generics yet.

If you're using an Ada 95 compiler, then you'll have to instantiate the
container packages at "library level," for subtle reasons.  (Things are
a lot simpler in Ada 05, and you'll be able to instantiate the
containers in a local scope.)



> When I tried to instantiate a hashed map, it seemed to want me to
> supply a hash function.

Then just use an ordered map.  Subtype Integer has a built-in less-than
operator, so you don't need anything extra to instantiate the ordered
map.


> OK, thanks for that. That second line ("L :") is particularly useful.

For now, it's probably easiest for you to just say:

procedure Op (M : Map_Subtype, K : Integer) is
   L : constant List_Subtype := Element (M, K);
begin
  ...



> > This is similar to the C++ code:
> >
> > void f(const map_t& m)
> > {
> >    const map_t::const_iterator i = m.find (2);
> >    const list_t& L = *i;
> >    //...
> > }

Actually, that should have been:

   const list_t& L = i.second;  //or i->second???


> Unfortunately, I'm unfamiliar with the STL. :-( But I can see the
> similarity.

The C++ declaration above creates a (const) reference to the map
element; it does not make a copy.  In your case, you element comprises
only a 2-tuple, so you probably don't need to worry about optimizing
away copy overhead.  (Ada and C++ are low-level, systems programming
languages, so we typically have to think about these things.)  Hence my
advice above, to simply say:

   L : constant List_Subtype := Element (M, K);




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

* Re: Charles container library usage examples
  2005-09-04  0:26   ` David Trudgett
  2005-09-04  9:49     ` Matthew Heaney
@ 2005-09-04 17:19     ` Ludovic Brenta
  2005-09-06  3:01       ` David Trudgett
  1 sibling, 1 reply; 29+ messages in thread
From: Ludovic Brenta @ 2005-09-04 17:19 UTC (permalink / raw)


David, in the past I also played with Charles and instantiated a
hashed map of Unbounded_Strings, which I used to represent the headers
in an email, and then a List_Of_Regexes.  You might be interested in
how I did the instantiations:

-- maps_of_headers.ads
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Charles.Hash_String;
with Charles.Maps.Hashed.Strings.Unbounded;

private package Maps_Of_Headers is
   new Charles.Maps.Hashed.Strings.Unbounded (Element_Type => Unbounded_String,
                                              Hash => Charles.Hash_String);

-- list_of_regexes.ads
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

with Charles.Vectors.Unbounded;

package Lists_Of_Regexes is
   new Charles.Vectors.Unbounded (Index_Type => Positive,
                                  Element_Type => Unbounded_String);

(This toy program served me well as a "Spam Killer", which is its
name; it reads a list of regular expressions in my .emacs file, uses a
POP3 Ada binding to query my mailbox, and deletes all email in the
mailbox that matches any of the regular expressions.  I used it from a
cron job and it would kill 50-100 spam mails a day, when my address
was under heavy attack.  Now the problem has subsided :) )

HTH

-- 
Ludovic Brenta.



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

* Re: Charles container library usage examples
  2005-09-04  6:25     ` David Trudgett
@ 2005-09-05 11:28       ` Georg Bauhaus
  0 siblings, 0 replies; 29+ messages in thread
From: Georg Bauhaus @ 2005-09-05 11:28 UTC (permalink / raw)


David Trudgett wrote:

> I was hoping to be able to just *use* a map without having to have
> detailed knowledge of how generics work.

Static typing at work, i.e. you have to say what kind of map
you want, with regard to the types involved. The compiler then
checks and allocates all sorts of things using compile time
information.


-- Georg 



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

* Re: Charles container library usage examples
  2005-09-04 17:19     ` Ludovic Brenta
@ 2005-09-06  3:01       ` David Trudgett
  2005-09-06  5:08         ` Ludovic Brenta
  2005-09-09 14:57         ` James Alan Farrell
  0 siblings, 2 replies; 29+ messages in thread
From: David Trudgett @ 2005-09-06  3:01 UTC (permalink / raw)


Hi Ludovic,

Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> David, in the past I also played with Charles and instantiated a
> hashed map of Unbounded_Strings, which I used to represent the headers
> in an email, and then a List_Of_Regexes.  You might be interested in
> how I did the instantiations:

Yes, those were very useful to me. I had already got to the stage of
trying this syntax:

> package Lists_Of_Regexes is
>    new Charles.Vectors.Unbounded (Index_Type => Positive,
>                                   Element_Type => Unbounded_String);

but your examples showed me that I was on the right track! What I
ended up with was:

----------------------------------------
-- file: side_corners_map.ads
with Charles.Maps.Sorted.Unbounded;
with Corner_List; use Corner_List;

package Side_Corners_Map is
   new Charles.Maps.Sorted.Unbounded (Key_Type => Integer,
                                      Element_Type => Corner_Pair);


----------------------------------------
-- file: corner_list.ads
package Corner_List is

   subtype Corner is Integer;
   subtype Pair is Integer range 1 .. 2;
   type Corner_Pair is array (Pair) of Corner;

end Corner_List;


----------------------------------------
-- file: class_board.ads
with Ada.Strings.Unbounded, Ada.Finalization, Side_Corners_Map;
use Ada.Strings.Unbounded, Ada.Finalization;

...

private

...

   Side_Corners : Side_Corners_Map.Container_Type;


----------------------------------------
-- file: class_board.adb
with Side_Corners_Map, Corner_List;
use Side_Corners_Map, Corner_List;

package body Class_Board is


   procedure Initialize (Self : in out Board) is
      Top    : Corner_Pair := (1, 3);
      Left   : Corner_Pair := (1, 7);
      Right  : Corner_Pair := (3, 9);
      Bottom : Corner_Pair := (7, 9);
   begin
      Reset(Self);
      Insert(Side_Corners, 2, Top);
      Insert(Side_Corners, 4, Left);
      Insert(Side_Corners, 6, Right);
      Insert(Side_Corners, 8, Bottom);
   end Initialize;



You can see I ditched the list for a simple array! I already had more
punishment than I cared for! ;-) I sort of don't mind going to this
much trouble for the advantages that Ada can give me over, say, Lisp
(which is what I'm translating from) in terms of execution speed, low
level control, native concurrency, etc. etc., but it *is* a fair bit
to replace five lines of unremarkable Lisp! :-) I was thinking that
the elaborateness of all this must provide a powerful disincentive for
Ada programmers to use collections/containers. Of course, if you
really need a collection, then you'll need to go to the trouble to
have one; but I'm thinking that there must be a whole lot of in
between cases where, although you can just get by with, say, arrays,
records, classes, even home-grown linked lists, and so on, it really
would be better to use the appropriate data structure and
algorithms. Anyway, that's just me daydreaming. Perhaps someone might
have something actually sensible to say about these thoughts.

I do have a couple of little questions about the code that I came up
with:

1. Is my INITIALIZE procedure more verbose than it needs to be? I
   wanted to put the array definitions inside the call to INSERT, but
   I don't think that's possible.

2. Did I need the separate file "corner_list.ads"? I tried to put it
   in "side_corners_map.ads", but the compiler didn't seem to like
   that idea.


Thanks,

David


-- 

David Trudgett
http://www.zeta.org.au/~wpower/

    Viking, n.:

    1. Daring Scandinavian seafarers, explorers, adventurers,
       entrepreneurs world-famous for their aggressive, nautical 
       import business, highly leveraged takeovers and blue eyes.
    
    2. Bloodthirsty sea pirates who ravaged northern Europe 
       beginning in the 9th century.

    Hagar's note: The first definition is much preferred; the 
    second is used only by malcontents, the envious, and disgruntled 
    owners of waterfront property.



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

* Re: Charles container library usage examples
  2005-09-04  9:49     ` Matthew Heaney
@ 2005-09-06  3:01       ` David Trudgett
  2005-09-06 16:22         ` Jeffrey Carter
  2005-09-07  0:15         ` Matthew Heaney
  0 siblings, 2 replies; 29+ messages in thread
From: David Trudgett @ 2005-09-06  3:01 UTC (permalink / raw)


"Matthew Heaney" <mheaney@on2.com> writes:

> Yes, you need to make two instantiations: one to create a list of
> integers, and another to create a map of lists.
>
> If your list always comprises two elements, then you can use a
> constrained array instead.  Something like:
>
>   type Integer_Array is array (Positive range <>) of Integer;
>   subtype Integer_Array_Subtype is Integer_Array (1 .. 2);
>
> or the simpler:
>
>    type Integer_Array is (1 .. 2) of Integer;

Yes, thanks. I used something similar. Using a list didn't give me
anything for the extra effort involved.



>
> Then you can use that as the generic actual Element_Type in the
> instantiation of the map (and hence get rid of the list instantiation
> entirely).

Good idea! ;-) :-)


> If you're using an Ada 95 compiler, then you'll have to instantiate the
> container packages at "library level," for subtle reasons.  (Things are
> a lot simpler in Ada 05, and you'll be able to instantiate the
> containers in a local scope.)

Yes, that will be a lot more convenient.


>> When I tried to instantiate a hashed map, it seemed to want me to
>> supply a hash function.
>
> Then just use an ordered map.  Subtype Integer has a built-in less-than
> operator, so you don't need anything extra to instantiate the ordered
> map.

Yep. I used the ordered map instead of the hashed map. By the way,
does Charles have general purpose hashing functions, or do you need to
roll your own? I thought I saw a string hash function in PragmARC. Is
it suitable for use in Charles?


> (Ada and C++ are low-level, systems programming languages, so we
> typically have to think about these things.)

Yep.


David



-- 

David Trudgett
http://www.zeta.org.au/~wpower/

Who would Jesus bomb?




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

* Re: Charles container library usage examples
  2005-09-06  3:01       ` David Trudgett
@ 2005-09-06  5:08         ` Ludovic Brenta
  2005-09-06  6:46           ` David Trudgett
  2005-09-09 14:57         ` James Alan Farrell
  1 sibling, 1 reply; 29+ messages in thread
From: Ludovic Brenta @ 2005-09-06  5:08 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease> writes:
> 1. Is my INITIALIZE procedure more verbose than it needs to be? I
>    wanted to put the array definitions inside the call to INSERT, but
>    I don't think that's possible.

procedure Initialize (Self : in out Board) is
begin
   Reset(Self);
   Insert(Side_Corners, 2, (1, 3));
   Insert(Side_Corners, 4, (1, 7));
   Insert(Side_Corners, 6, (3, 9));
   Insert(Side_Corners, 8, (7, 9));
end Initialize;

> 2. Did I need the separate file "corner_list.ads"? I tried to put it
>    in "side_corners_map.ads", but the compiler didn't seem to like
>    that idea.

Yes, you need one because Side_Corner_Maps must be instantiated at
"library level".  This prevents dangling references to nested types.

-- 
Ludovic Brenta.




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

* Re: Charles container library usage examples
  2005-09-06  5:08         ` Ludovic Brenta
@ 2005-09-06  6:46           ` David Trudgett
  2005-09-06  7:26             ` Ludovic Brenta
  0 siblings, 1 reply; 29+ messages in thread
From: David Trudgett @ 2005-09-06  6:46 UTC (permalink / raw)


Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> David Trudgett <wpower@zeta.org.au.nospamplease> writes:
>> 1. Is my INITIALIZE procedure more verbose than it needs to be? I
>>    wanted to put the array definitions inside the call to INSERT, but
>>    I don't think that's possible.
>
> procedure Initialize (Self : in out Board) is
> begin
>    Reset(Self);
>    Insert(Side_Corners, 2, (1, 3));
>    Insert(Side_Corners, 4, (1, 7));
>    Insert(Side_Corners, 6, (3, 9));
>    Insert(Side_Corners, 8, (7, 9));
> end Initialize;

Oops! Well, how about that! I thought I tried that, but obviously
not. I've changed it now and it works fine! Thank you.


>
>> 2. Did I need the separate file "corner_list.ads"? I tried to put it
>>    in "side_corners_map.ads", but the compiler didn't seem to like
>>    that idea.
>
> Yes, you need one because Side_Corner_Maps must be instantiated at
> "library level".  This prevents dangling references to nested types.

OK ;-) I'll take your word for it... ;-) 


Cheers,

David



-- 

David Trudgett
http://www.zeta.org.au/~wpower/

"Nasty, tricksy parenthesises. We hates them!"

    -- Sampo Smolander




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

* Re: Charles container library usage examples
  2005-09-06  6:46           ` David Trudgett
@ 2005-09-06  7:26             ` Ludovic Brenta
  2005-09-24  0:05               ` Randy Brukardt
  0 siblings, 1 reply; 29+ messages in thread
From: Ludovic Brenta @ 2005-09-06  7:26 UTC (permalink / raw)


David Trudgett a écrit :
> >> 2. Did I need the separate file "corner_list.ads"? I tried to put it
> >>    in "side_corners_map.ads", but the compiler didn't seem to like
> >>    that idea.
> >
> > Yes, you need one because Side_Corner_Maps must be instantiated at
> > "library level".  This prevents dangling references to nested types.
>
> OK ;-) I'll take your word for it... ;-)

Somebody else might elaborate on how Ada 200y is making this rule more
subtle, so that library level instantiations are no longer necessary
in some cases; I'm actually curious to better understand this change.
Anyone?

-- 
Ludovic Brenta.




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

* Re: Charles container library usage examples
  2005-09-06  3:01       ` David Trudgett
@ 2005-09-06 16:22         ` Jeffrey Carter
  2005-09-07  0:15         ` Matthew Heaney
  1 sibling, 0 replies; 29+ messages in thread
From: Jeffrey Carter @ 2005-09-06 16:22 UTC (permalink / raw)


David Trudgett wrote:
> 
> Yep. I used the ordered map instead of the hashed map. By the way,
> does Charles have general purpose hashing functions, or do you need to
> roll your own? I thought I saw a string hash function in PragmARC. Is
> it suitable for use in Charles?

The PragmAda Reusable Components contain an implementation of Pearson's 
hashing function for Strings. This function returns a byte as the hash 
value. This is not directly appropriate for the components in 
Ada.Containers, which require a much larger range of values. Whether it 
is appropriate for the Charles library is another question, and not one 
I can answer.

-- 
Jeffrey Carter
"Now go away or I shall taunt you a second time."
Monty Python and the Holy Grail
E-mail: jeffrey_r_carter-nr [commercial-at]
         raytheon [period | full stop] com



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

* Re: Charles container library usage examples
  2005-09-06  3:01       ` David Trudgett
  2005-09-06 16:22         ` Jeffrey Carter
@ 2005-09-07  0:15         ` Matthew Heaney
  1 sibling, 0 replies; 29+ messages in thread
From: Matthew Heaney @ 2005-09-07  0:15 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

> Yep. I used the ordered map instead of the hashed map. By the way,
> does Charles have general purpose hashing functions, or do you need to
> roll your own? I thought I saw a string hash function in PragmARC. Is
> it suitable for use in Charles?

Charles has a hash function for type String; see the files:

charles-hash_string.ad[sb]

There's also a hash function for type Integer:

charles-hash_integer.ad[sb]

In your case, you have an integer key, so you can use the Hash_Integer
function already provided by Charles.  

Except for Hash_String and Hash_Integer, there are no "general-purpose"
hash functions, since writing a hash function often requires a modest
amount of tuning over expected inputs.

-Matt




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

* Re: Charles container library usage examples
  2005-09-06  3:01       ` David Trudgett
  2005-09-06  5:08         ` Ludovic Brenta
@ 2005-09-09 14:57         ` James Alan Farrell
  2005-09-10  7:38           ` David Trudgett
  1 sibling, 1 reply; 29+ messages in thread
From: James Alan Farrell @ 2005-09-09 14:57 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1749 bytes --]

> You can see I ditched the list for a simple array! I already had more
> punishment than I cared for! ;-) I sort of don't mind going to this
> much trouble for the advantages that Ada can give me over, say, Lisp
> (which is what I'm translating from) in terms of execution speed, low
> level control, native concurrency, etc. etc., but it *is* a fair bit
> to replace five lines of unremarkable Lisp! :-) I was thinking that
> the elaborateness of all this must provide a powerful disincentive for
> Ada programmers to use collections/containers. Of course, if you
> really need a collection, then you'll need to go to the trouble to
> have one; but I'm thinking that there must be a whole lot of in
> between cases where, although you can just get by with, say, arrays,
> records, classes, even home-grown linked lists, and so on, it really
> would be better to use the appropriate data structure and
> algorithms. Anyway, that's just me daydreaming. Perhaps someone might
> have something actually sensible to say about these thoughts.

I'm never sure if my opinions are sensible or not, but...

All languages have strengths, or they would dissappear through disuse. 
The strengths of different languages must be different or we'd have just 
  one language.  Therefor all languages must also have (comparative) 
weaknesses.

One strength of Lisp is how easy it is to use dynamic data structures. 
But it has weaknesses in weak typing and slow execution.

Setting up the Charles library seems to me about equal in lines of code 
and what you have to know to setting up STLs in C++.  The first few 
times is quite confusing and frustrating, but it gets easier as you do 
it more often.  It is still easier than creating your own from scratch.

JAF

[-- Attachment #2: jfarrell.vcf --]
[-- Type: text/x-vcard, Size: 88 bytes --]

begin:vcard
fn:James Alan Farrell
n:Farrell;James
org:GrammaTech
version:2.1
end:vcard


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

* Re: Charles container library usage examples
  2005-09-09 14:57         ` James Alan Farrell
@ 2005-09-10  7:38           ` David Trudgett
  2005-09-10 14:55             ` Matthew Heaney
                               ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: David Trudgett @ 2005-09-10  7:38 UTC (permalink / raw)


James Alan Farrell <jfarrell@nospam.com> writes:

>> You can see I ditched the list for a simple array! I already had more
>> punishment than I cared for! ;-) I sort of don't mind going to this
>> much trouble for the advantages that Ada can give me over, say, Lisp
>> (which is what I'm translating from) in terms of execution speed, low
>> level control, native concurrency, etc. etc., but it *is* a fair bit
>> to replace five lines of unremarkable Lisp! :-) I was thinking that
>> the elaborateness of all this must provide a powerful disincentive for
>> Ada programmers to use collections/containers. Of course, if you
>> really need a collection, then you'll need to go to the trouble to
>> have one; but I'm thinking that there must be a whole lot of in
>> between cases where, although you can just get by with, say, arrays,
>> records, classes, even home-grown linked lists, and so on, it really
>> would be better to use the appropriate data structure and
>> algorithms. Anyway, that's just me daydreaming. Perhaps someone might
>> have something actually sensible to say about these thoughts.
>
> I'm never sure if my opinions are sensible or not, but...
>
> All languages have strengths, or they would dissappear through
> disuse. 

Probably true to some (a great?) extent. It also depends a bit on what
you call a "strength"! For example, COBOL survives mostly because of
the huge momentum behind it, including the massive amount of
commercial software written in it. COBOL's "strength" is that it was
first to fill the niche! :-) Other languages' strengths include the
amount of clout put into their marketing! ;-) (And the concomitant
market share this creates.) Of course, they do have to have some other
strengths in addition, or they wouldn't be doing as well as they
are. So it's not black and white.

The other side of the coin is that languages *have* (virtually)
disappeared, but not necessarily because they didn't have strengths. I
think it is most likely fair to say (though, of course, not a logical
deduction) that if languages can disappear for reasons other than
their strengths, then other languages can probably linger on despite
lack of strengths.


> The strengths of different languages must be different or we'd
> have just one language.  Therefor all languages must also have
> (comparative) weaknesses.

Yes, it's hard to imagine a super-language for everything.


>
> One strength of Lisp is how easy it is to use dynamic data
> structures. But it has weaknesses in weak typing and slow execution.

Well, that's true from the Ada programmer's perspective, however
Lispers generally don't think weak typing is a weakness, but rather a
strength (but device drivers, for instance, don't generally get
written in Lisp, I think, so we get back to horses for courses). 

Slow execution is also somewhat relative. Ada is slower than C, for
instance, unless you disable run-time checks (an Ada strength), and
even then Ada may still have extra features/overhead that C doesn't
have. Similarly, Lisp has features/overhead that Ada doesn't have, and
time (or space) penalties to go with them.

Lisp is good for an experimental/exploratory/evolutionary/incremental
style of programming, with modern compilers producing very good
execution speeds for most problem domains; whereas Ada is great for a
software engineering approach, and has excellent strengths in areas
like safety, portability, etc, which you all know.

Anyway, my main purpose now is learning Ada, because it definitely has
valuable strengths not found in other languages I've used, like Pascal
(various), C, Perl, Python, and lately, Common Lisp.



>
> Setting up the Charles library seems to me about equal in lines of
> code and what you have to know to setting up STLs in C++.  

I made light use of a container library for Delphi, and didn't have
any great problems with it (besides getting my head around concepts
like iterator). I'd say it was easier to use than Charles because
there was no concern about instantiating generic packages, nor any
requirement to create multiple source files.


> The first few times is quite confusing and frustrating, but it gets
> easier as you do it more often.  

Definitely so! I don't expect to have too much trouble in future, now
that I've worked through the initial issues.


> It is still easier than creating your own from scratch.

Yes, indeed!


David



-- 

David Trudgett
http://www.zeta.org.au/~wpower/

The recognition or non-recognition of a certain truth depends not on
external causes, but on certain other causes within the man himself.
So that at times under external conditions apparently very favorable
for the recognition of truth, one man will not recognize it, and
another, on the contrary, under the most unfavorable conditions will,
without apparent cause, recognize it.

    -- Leo Tolstoy




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

* Re: Charles container library usage examples
  2005-09-10  7:38           ` David Trudgett
@ 2005-09-10 14:55             ` Matthew Heaney
  2005-09-10 15:26               ` Ludovic Brenta
  2005-09-12  0:24               ` Robert A Duff
  2005-09-11 10:52             ` Georg Bauhaus
  2005-09-12  0:21             ` Robert A Duff
  2 siblings, 2 replies; 29+ messages in thread
From: Matthew Heaney @ 2005-09-10 14:55 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

> I'd say it was easier to use than Charles because there was no concern
> about instantiating generic packages, nor any requirement to create
> multiple source files.

That last part about multiple files in only true in Ada95.  In Ada 2005,
you'll be able to instantiate generic container packages in a local
scope, hence only a single file will be necessary.



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

* Re: Charles container library usage examples
  2005-09-10 14:55             ` Matthew Heaney
@ 2005-09-10 15:26               ` Ludovic Brenta
  2005-09-10 17:58                 ` Matthew Heaney
  2005-09-12  0:24               ` Robert A Duff
  1 sibling, 1 reply; 29+ messages in thread
From: Ludovic Brenta @ 2005-09-10 15:26 UTC (permalink / raw)


Matthew Heaney <matthewjheaney@earthlink.net> writes:

> David Trudgett <wpower@zeta.org.au.nospamplease>  writes:
>
>> I'd say it was easier to use than Charles because there was no concern
>> about instantiating generic packages, nor any requirement to create
>> multiple source files.
>
> That last part about multiple files in only true in Ada95.  In Ada 2005,
> you'll be able to instantiate generic container packages in a local
> scope, hence only a single file will be necessary.

Yes.  I read about that in John Barnes' "Rationale for Ada 2005" (in
"Ada User Journal", volume 26, number 1, page 53).  This apparently
requires the introduction of some run-time checks.  Do Ada.Containers
try to avoid such run-time checks?  How?

And is there a way (pragma Restrictions?) to forbid these run-time
checks?

-- 
Ludovic Brenta.



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

* Re: Charles container library usage examples
  2005-09-10 15:26               ` Ludovic Brenta
@ 2005-09-10 17:58                 ` Matthew Heaney
  0 siblings, 0 replies; 29+ messages in thread
From: Matthew Heaney @ 2005-09-10 17:58 UTC (permalink / raw)


Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> Yes.  I read about that in John Barnes' "Rationale for Ada 2005" (in
> "Ada User Journal", volume 26, number 1, page 53).  This apparently
> requires the introduction of some run-time checks.  Do Ada.Containers
> try to avoid such run-time checks?  How?

Those checks aren't done by the containers themselves.  They're done by
a lower-level part of the run-time (I think related to derivation and
streaming attributes, but I'm not really sure).  I think Gary Dismukes
implemented that part of the GNAT run-time, so he'd be the guy to ask.
Javier Miranda might know too.


> And is there a way (pragma Restrictions?) to forbid these run-time
> checks?

I'm not sure.  My knowledge of the Ada 2005 language revision is rather
parochial, as you can imagine...

Draft 13 of Ada Amendment 1 was just released, so lately I've been busy
synchronizing the GCC sources with what's described in the draft.  I've
also been adding checks (some controlled by pragma Assert, some not) to
detect dangling cursors, per the CLA thread a few weeks ago.



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

* Re: Charles container library usage examples
  2005-09-10  7:38           ` David Trudgett
  2005-09-10 14:55             ` Matthew Heaney
@ 2005-09-11 10:52             ` Georg Bauhaus
  2005-09-11 21:14               ` David Trudgett
  2005-09-12  0:21             ` Robert A Duff
  2 siblings, 1 reply; 29+ messages in thread
From: Georg Bauhaus @ 2005-09-11 10:52 UTC (permalink / raw)


David Trudgett wrote:

> Slow execution is also somewhat relative. Ada is slower than C, for
> instance, unless you disable run-time checks (an Ada strength), and
> even then Ada may still have extra features/overhead that C doesn't
> have.

There is some overhead in C programs, too, when they have explicit
checking code to compensate for what C doesn't have. This code isn't
necessarily visible to the C compiler as checking code, I 'd say,
whereas checks implied by the Ada language are visible to the compiler
in this sense.




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

* Re: Charles container library usage examples
  2005-09-11 10:52             ` Georg Bauhaus
@ 2005-09-11 21:14               ` David Trudgett
  2005-09-13 23:41                 ` Björn Persson
  0 siblings, 1 reply; 29+ messages in thread
From: David Trudgett @ 2005-09-11 21:14 UTC (permalink / raw)


Georg Bauhaus <bauhaus@futureapps.de> writes:

> David Trudgett wrote:
>
>> Slow execution is also somewhat relative. Ada is slower than C, for
>> instance, unless you disable run-time checks (an Ada strength), and
>> even then Ada may still have extra features/overhead that C doesn't
>> have.
>
> There is some overhead in C programs, too, when they have explicit
> checking code to compensate for what C doesn't have. 

Yes, this is quite true[1], in theory, as well as no doubt in practice (I
don't have heaps of experience in the C world, so that's all I can
say). On the other hand, with C, you only have to overlook or forget,
or have over-towering confidence in one's coding ability, or not know
any better, and that's it, you've shot yourself in the foot, so to
speak (but you've done it real fast!). Ada feels a lot, LOT safer! :-)

I was just writing some Ada code yesterday. It was a case statement
and I had forgotten to take care of one possible case. Naturally, the
Ada compiler helpfully reminded me. This isn't a run-time check, of
course, but still useful.

On the subject of about compiler reminders, I'm also very impressed by
Gnat's error and warning messages. Talk about helpful! I've never used
a compiler with clearer or more useful messages. "You have mispelled
'return'" (or similar) is just one minor example that comes to mind! :-)


> This code isn't necessarily visible to the C compiler as checking
> code, I 'd say, whereas checks implied by the Ada language are
> visible to the compiler in this sense.

I'm not sure what the point is here. What does being "visible" to the
compiler mean in that sense? Is that more important than the simple
fact of being present (because the Ada compiler ensures it is)?


David

[1] It is also true in the case people accuse Lisp, for example, of
being slow. If other languages actually did the things that Lisp does,
there wouldn't be any talk about speed differences!

-- 

David Trudgett
http://www.zeta.org.au/~wpower/

The operative definition of "crime" is: "Crime that you carried out
but we did not." To underscore the fact, Nazi war criminals were
absolved if the defense could show that their US counterparts carried
out the same crimes.

Taylor concludes that "to punish the foe -- especially the vanquished
foe -- for conduct in which the enforcer nation has engaged, would be
so grossly inequitable as to discredit the laws themselves." That is
correct, but the operative definition also discredits the laws
themselves, along with all subsequent tribunals.  Taylor provides this
background as part of his explanation of why US bombing in Vietnam was
not a war crime.  His argument is plausible, further discrediting the
laws themselves.  Some of the subsequent judicial inquiries are
discredited in perhaps even more extreme ways, such as the Yugoslavia
vs. NATO case now being adjudicated by the International Court of
Justice.  The US was excused, correctly, on the basis of its argument
that it is not subject to the jurisdiction of the Court in this case.
The reason is that when the US finally signed the Genocide Convention
(which is at issue here) after 40 years, it did so with a reservation
stating that it is inapplicable to the United States.

    -- Noam Chomsky
       <http://www.chomsky.info/articles/20041217.htm>



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

* Re: Charles container library usage examples
  2005-09-10  7:38           ` David Trudgett
  2005-09-10 14:55             ` Matthew Heaney
  2005-09-11 10:52             ` Georg Bauhaus
@ 2005-09-12  0:21             ` Robert A Duff
  2005-09-12  0:57               ` David Trudgett
  2 siblings, 1 reply; 29+ messages in thread
From: Robert A Duff @ 2005-09-12  0:21 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

> Slow execution is also somewhat relative. Ada is slower than C, for
> instance, unless you disable run-time checks (an Ada strength),

It seems to me that a language that allows run-time array-bounds
checking to be turned on or off, at the programmers whim, is clearly
superior to a language that turns it on/off at language design time.

>... and
> even then Ada may still have extra features/overhead that C doesn't
> have.

That's true.  Ada programs still have to store the array bounds in
memory, even if array-bounds checking is turned off.

>... Similarly, Lisp has features/overhead that Ada doesn't have, and
> time (or space) penalties to go with them.

True.

- Bob



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

* Re: Charles container library usage examples
  2005-09-10 14:55             ` Matthew Heaney
  2005-09-10 15:26               ` Ludovic Brenta
@ 2005-09-12  0:24               ` Robert A Duff
  1 sibling, 0 replies; 29+ messages in thread
From: Robert A Duff @ 2005-09-12  0:24 UTC (permalink / raw)


Matthew Heaney <matthewjheaney@earthlink.net> writes:

> David Trudgett <wpower@zeta.org.au.nospamplease>  writes:
> 
> > I'd say it was easier to use than Charles because there was no concern
> > about instantiating generic packages, nor any requirement to create
> > multiple source files.
> 
> That last part about multiple files in only true in Ada95.  In Ada 2005,
> you'll be able to instantiate generic container packages in a local
> scope, hence only a single file will be necessary.

True, but even in Ada 95 you can instantiate a generic package inside
another package.  So there's not always a need to have separate files.
There are some problems with the freezing rules, however...

- Bob



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

* Re: Charles container library usage examples
  2005-09-12  0:21             ` Robert A Duff
@ 2005-09-12  0:57               ` David Trudgett
  2005-09-12  1:01                 ` Robert A Duff
  0 siblings, 1 reply; 29+ messages in thread
From: David Trudgett @ 2005-09-12  0:57 UTC (permalink / raw)


Robert A Duff <bobduff@shell01.TheWorld.com> writes:

> David Trudgett <wpower@zeta.org.au.nospamplease>  writes:
>
>> Slow execution is also somewhat relative. Ada is slower than C, for
>> instance, unless you disable run-time checks (an Ada strength),
>
> It seems to me that a language that allows run-time array-bounds
> checking to be turned on or off, at the programmers whim, is clearly
> superior to a language that turns it on/off at language design time.

But it must be difficult to code buffer overflows in Ada... ;-) A lot
of popular software wouldn't be possible without them!

David


-- 

David Trudgett
http://www.zeta.org.au/~wpower/

What I don't know is not as much of a problem
as what I am sure I know that just ain't so.

    -- Mark Twain




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

* Re: Charles container library usage examples
  2005-09-12  0:57               ` David Trudgett
@ 2005-09-12  1:01                 ` Robert A Duff
  0 siblings, 0 replies; 29+ messages in thread
From: Robert A Duff @ 2005-09-12  1:01 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

> Robert A Duff <bobduff@shell01.TheWorld.com> writes:
> 
> > David Trudgett <wpower@zeta.org.au.nospamplease>  writes:
> >
> >> Slow execution is also somewhat relative. Ada is slower than C, for
> >> instance, unless you disable run-time checks (an Ada strength),
> >
> > It seems to me that a language that allows run-time array-bounds
> > checking to be turned on or off, at the programmers whim, is clearly
> > superior to a language that turns it on/off at language design time.
> 
> But it must be difficult to code buffer overflows in Ada... ;-) A lot
> of popular software wouldn't be possible without them!

;-)

- Bob



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

* Re: Charles container library usage examples
  2005-09-11 21:14               ` David Trudgett
@ 2005-09-13 23:41                 ` Björn Persson
  2005-09-14  6:39                   ` David Trudgett
  0 siblings, 1 reply; 29+ messages in thread
From: Björn Persson @ 2005-09-13 23:41 UTC (permalink / raw)


David Trudgett wrote:
> Georg Bauhaus <bauhaus@futureapps.de> writes:
>>This code isn't necessarily visible to the C compiler as checking
>>code, I 'd say, whereas checks implied by the Ada language are
>>visible to the compiler in this sense.
> 
> I'm not sure what the point is here. What does being "visible" to the
> compiler mean in that sense? Is that more important than the simple
> fact of being present (because the Ada compiler ensures it is)?

The Ada compiler can omit checks if it can prove that they will never 
fail. While even the C compiler can optimize away code that will never 
have any effect, I would think it's a lot more difficult to prove that a 
hand-coded run-time check is unnecessary when the compiler doesn't know 
what it's for.

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



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

* Re: Charles container library usage examples
  2005-09-13 23:41                 ` Björn Persson
@ 2005-09-14  6:39                   ` David Trudgett
  0 siblings, 0 replies; 29+ messages in thread
From: David Trudgett @ 2005-09-14  6:39 UTC (permalink / raw)


Bj�rn Persson <spam-away@nowhere.nil> writes:

>
> The Ada compiler can omit checks if it can prove that they will never
> fail. While even the C compiler can optimize away code that will never
> have any effect, I would think it's a lot more difficult to prove that
> a hand-coded run-time check is unnecessary when the compiler doesn't
> know what it's for.

Fair enough, that sounds plausible. Of course, if one were writing
checking code in C, for instance, one would probably surround it with
IFDEFs so it could be manually excluded after testing. Not as granular
and tidy, perhaps, as automatic suppression of redundant checks, but
similar, nonetheless.

Cheers,

David



-- 

David Trudgett
http://www.zeta.org.au/~wpower/

Omnis enim res, quae dando non deficit, dum habetur
     et non datur, nondum habetur, quomodo habenda est.

For if a thing is not diminished by being shared with others,
     it is not rightly owned if it is only owned and not shared.

Book I, Chapter 1 "De doctrina christiana"
"Corpus Christianorum", "Series latina", Vol. 32, p. 6, lines 10-11.
Written 397 AD by Saint Augustinus




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

* Re: Charles container library usage examples
  2005-09-06  7:26             ` Ludovic Brenta
@ 2005-09-24  0:05               ` Randy Brukardt
  0 siblings, 0 replies; 29+ messages in thread
From: Randy Brukardt @ 2005-09-24  0:05 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]

"Ludovic Brenta" <ludovic@ludovic-brenta.org> wrote in message
news:1125991591.402272.176230@g47g2000cwa.googlegroups.com...
>David Trudgett a �crit :
>> >> 2. Did I need the separate file "corner_list.ads"? I tried to put it
>> >>    in "side_corners_map.ads", but the compiler didn't seem to like
>> >>    that idea.
>> >
>> > Yes, you need one because Side_Corner_Maps must be instantiated at
>> > "library level".  This prevents dangling references to nested types.
>>
>> OK ;-) I'll take your word for it... ;-)
>
>Somebody else might elaborate on how Ada 200y is making this rule more
>subtle, so that library level instantiations are no longer necessary
>in some cases; I'm actually curious to better understand this change.
>Anyone?

The quicky answer (now that I'm back from vacation and catching up here):
Tucker Taft did an analysis and determined that the only cases where a
(tagged) object could outlive its type were (1) objects that were returned;
(2) objects that were allocated (for outer access types). Thus, it made
sense to move the accessibility checks to those two locations, and allow the
(nested) type extensions and objects of them (except in the previous two
cases).

This makes a ton of sense from a usability prespective (its too bad that it
wasn't realized for Ada 95), but it does make type extensions significantly
harder to implement.

                             Randy.



--
Ludovic Brenta.






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

end of thread, other threads:[~2005-09-24  0:05 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-03  2:38 Charles container library usage examples David Trudgett
2005-09-03  5:15 ` Matthew Heaney
2005-09-03  9:45   ` Simon Wright
2005-09-04  6:25     ` David Trudgett
2005-09-05 11:28       ` Georg Bauhaus
2005-09-04  0:26   ` David Trudgett
2005-09-04  9:49     ` Matthew Heaney
2005-09-06  3:01       ` David Trudgett
2005-09-06 16:22         ` Jeffrey Carter
2005-09-07  0:15         ` Matthew Heaney
2005-09-04 17:19     ` Ludovic Brenta
2005-09-06  3:01       ` David Trudgett
2005-09-06  5:08         ` Ludovic Brenta
2005-09-06  6:46           ` David Trudgett
2005-09-06  7:26             ` Ludovic Brenta
2005-09-24  0:05               ` Randy Brukardt
2005-09-09 14:57         ` James Alan Farrell
2005-09-10  7:38           ` David Trudgett
2005-09-10 14:55             ` Matthew Heaney
2005-09-10 15:26               ` Ludovic Brenta
2005-09-10 17:58                 ` Matthew Heaney
2005-09-12  0:24               ` Robert A Duff
2005-09-11 10:52             ` Georg Bauhaus
2005-09-11 21:14               ` David Trudgett
2005-09-13 23:41                 ` Björn Persson
2005-09-14  6:39                   ` David Trudgett
2005-09-12  0:21             ` Robert A Duff
2005-09-12  0:57               ` David Trudgett
2005-09-12  1:01                 ` Robert A Duff

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