comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
@ 2005-07-25 17:45 ` Marc A. Criley
  2005-07-25 17:47 ` Simon Clubley
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 48+ messages in thread
From: Marc A. Criley @ 2005-07-25 17:45 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> To anyone interested,
> 
> I very urgently need this ada 95 package written for me and I am
> willing to pay anyone for their time. Here is the specification;
> 
> The is supposed to be a basic database to monitor a group of made up
> citizens and their badness rating.
>
> Again, if anyone is interested I'm willing to pay for your services.

How much are homework assignments going for nowadays?  :-)



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

* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
  2005-07-25 17:45 ` Help needed for ada package Marc A. Criley
@ 2005-07-25 17:47 ` Simon Clubley
  2005-07-25 18:21   ` Georg Bauhaus
  2005-07-25 18:46 ` Frank J. Lhota
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 48+ messages in thread
From: Simon Clubley @ 2005-07-25 17:47 UTC (permalink / raw)


In article <1122305318.728942.304120@f14g2000cwb.googlegroups.com>, strictly_mk@hotmail.com writes:
> To anyone interested,
> 
> I very urgently need this ada 95 package written for me and I am
> willing to pay anyone for their time. Here is the specification;
> 
> The is supposed to be a basic database to monitor a group of made up
> citizens and their badness rating.
> 

[snip]

At least you didn't ask someone to design a weapons system for you. :-)

I am trying to decide if this is a troll or a homework assignment.

Assuming that it's the latter, paying someone to do your homework for
you is only a short term solution. Part of doing homework is learning
_how_ to solve problems.

When people want help with homework, they usually ask a very specific
question, along with posting the code that they have tried to date.

If you are stuck on the problem as a whole, can't your tutor give you
some guidance on getting started ?

Sorry that I can't be more help, but we've all faced these problems
while learning, and learning how to overcome them is a required part of
the learning process.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP       
Microsoft: The Standard Oil Company of the 21st century



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

* Re: Help needed for ada package
  2005-07-25 17:47 ` Simon Clubley
@ 2005-07-25 18:21   ` Georg Bauhaus
  0 siblings, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-07-25 18:21 UTC (permalink / raw)


Simon Clubley wrote:
> In article <1122305318.728942.304120@f14g2000cwb.googlegroups.com>, strictly_mk@hotmail.com writes:

>>The is supposed to be a basic database to monitor a group of made up
>>citizens and their badness rating.

> At least you didn't ask someone to design a weapons system for you. :-)
> 
> I am trying to decide if this is a troll or a homework assignment.

I'm trying to figure out what badness is, here. Or a bad citizen.
So far I have learned that in English, "He's bad!" can be a statement
approving of someone's favorable qualities. OTOH, the political
pendulum is currently swinging to the watchers side, so we might
be witnessing another large scale surveillance project.

Could someone do me a favor and elucidate?

TIA,
Georg 




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

* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
  2005-07-25 17:45 ` Help needed for ada package Marc A. Criley
  2005-07-25 17:47 ` Simon Clubley
@ 2005-07-25 18:46 ` Frank J. Lhota
  2005-07-25 19:26 ` tmoran
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 48+ messages in thread
From: Frank J. Lhota @ 2005-07-25 18:46 UTC (permalink / raw)


When you're done, I want to run this program to measure the badness of 
Michael Jackson.



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

* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
                   ` (2 preceding siblings ...)
  2005-07-25 18:46 ` Frank J. Lhota
@ 2005-07-25 19:26 ` tmoran
  2005-07-25 22:12 ` Ludovic Brenta
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 48+ messages in thread
From: tmoran @ 2005-07-25 19:26 UTC (permalink / raw)


How many groups might a given citizen belong too?  With 10**6 citizens,
there are potentially 2**(10**6) subgroups (subtract 10**6 if loners
are not considered groups).



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

* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
                   ` (3 preceding siblings ...)
  2005-07-25 19:26 ` tmoran
@ 2005-07-25 22:12 ` Ludovic Brenta
  2005-07-25 23:33 ` Jeffrey Carter
  2005-07-26  3:17 ` Steve
  6 siblings, 0 replies; 48+ messages in thread
From: Ludovic Brenta @ 2005-07-25 22:12 UTC (permalink / raw)


strictly_mk@hotmail.com writes:
> I very urgently need this ada 95 package written for me and I am
> willing to pay anyone for their time. Here is the specification;
[...]
> Rate is supposed to enter a citizen with his/her ID (integer) and their
> badness (integer) into the database.
[...]
> There will be no more than 1 million citizens entered. Updates should
> be optimised at the expense of queries. Do not worry too much about
> error handling.
>
> The program is supposed to be compiled on gnat. I require both the code
> and a compiled file.
>
> Again, if anyone is interested I'm willing to pay for your services.

I don't think this is homework; I think it's worse than that.  Some
unknown group of unknown people are asking us to write a database
containing actual person records in it.  We don't know what country
the database will run in, what people will have their records in it,
what is the definition of "badness", and, most importantly, we don't
even know what this unknown group of people is planning to do with the
"bad" people.

"strictly_mk", who are you anyway?  If you don't have the time to
learn Ada, that's fine and fair but could you please elaborate on the
more important questions I raised?

-- 
Ludovic Brenta.



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

* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
                   ` (4 preceding siblings ...)
  2005-07-25 22:12 ` Ludovic Brenta
@ 2005-07-25 23:33 ` Jeffrey Carter
  2005-07-26 17:29   ` Pascal Obry
  2005-07-26  3:17 ` Steve
  6 siblings, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2005-07-25 23:33 UTC (permalink / raw)


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

strictly_mk@hotmail.com wrote:
> 
> I very urgently need this ada 95 package written for me and I am
> willing to pay anyone for their time. Here is the specification;

Sounds good. I could do it for only $20 million, cash, in new $100 bills.

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

begin:vcard
fn:Jeffrey Carter
n:;Jeffrey Carter
email;internet:jeffrey_r_carter-nr [commercial-at] raytheon [period | full stop] com
x-mozilla-html:FALSE
version:2.1
end:vcard


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

* Re: Help needed for ada package
       [not found] <1122320036.858648.242630@f14g2000cwb.googlegroups.com>
@ 2005-07-26  0:47 ` tmoran
  0 siblings, 0 replies; 48+ messages in thread
From: tmoran @ 2005-07-26  0:47 UTC (permalink / raw)


>Potentially, it is possible an individual is associated with everyone
>else hence there being one group of one million or 999999 pairs of groups.
  "Group" is misleading here.  Your "procedure Associate" leads to a
symmetric boolean N x N matrix where M(I,J) is True iff person I and
person J have ever been associated.  Finding the worst citizen in the same
"group" as citizen X means finding everyone X knows, then for each of X's
associates, finding all their associates, for each of those finding all
their associates, etc etc, and noting the worst person you come across.
If this is a brand new police database, then there are probably very few
known associations, so that's not too terrible in either storage or time.
  If you've been monitoring all associations between any two people over
the last many years, everybody is "associated" with several hundred
others, each of whom is associated with several hundred, and so forth.
Evemtually you'll find that, as in "six degrees of Kevin Bacon",
everyone except for a few cloistered nuns is associated with Kevin Bacon,
and thus with each other, so there are only two groups - those citizens
"associated" with Kevin Bacon and those in the nunnery.  Assuming there's
someone more dangerous than the nuns, Next_Member will simply be an
enumeration of all non-nuns.  Is that useful?



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

* Re: Help needed for ada package
       [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
                   ` (5 preceding siblings ...)
  2005-07-25 23:33 ` Jeffrey Carter
@ 2005-07-26  3:17 ` Steve
       [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
       [not found]   ` <1123173235.773051.23360@z14g2000cwz.googlegroups.com>
  6 siblings, 2 replies; 48+ messages in thread
From: Steve @ 2005-07-26  3:17 UTC (permalink / raw)



<strictly_mk@hotmail.com> wrote in message 
news:1122305318.728942.304120@f14g2000cwb.googlegroups.com...
> To anyone interested,
>
> I very urgently need this ada 95 package written for me and I am
> willing to pay anyone for their time. Here is the specification;
>
> The is supposed to be a basic database to monitor a group of made up
> citizens and their badness rating.
>
> generic
>    type ID is (<>); --some discrete type to be put here
> package POP is
>   --update database
>  type Rating is new Integer range 0..255;
>  procedure Rate (Citizen : in ID;
>                           Badness : in Rating);
>  procedure Associate (Citizen_1, Citizen_2 : in ID);
>  --query the database
>  function Most_Dangerous return ID;
>  function Next_Member return ID;
>  function More_In_Group return Boolean;
>  --administrative
>  procedure reset;
> end POP;
>

Sorry I don't have enough time to write the whole thing write now, but 
here's a start (maybe someone else will step in to fill in another routine):

with Ada.Unchecked_Deallocation;
package body POP is

  type
  RO0O is record  lll1 : ID;  ll1l : Rating; end record; type
  ROO0 is array( positive range <> ) of
  RO0O; type R0OO is access all ROO0;

  procedure RO00 is new Ada.Unchecked_Deallocation( ROO0, R0OO );

  R00O : R0OO;  R0O0 : Natural := 0;

   procedure Associate (Citizen_1, Citizen_2 : in ID) is
   begin
      null;
   end Associate;

   function More_In_Group return Boolean is
   begin
      return More_In_Group;
   end More_In_Group;

   function Most_Dangerous return ID is
   begin
      return Most_Dangerous;
   end Most_Dangerous;

   function Next_Member return ID is
   begin
      return Next_Member;
   end Next_Member;

   procedure Rate
     (Citizen : in ID; Badness : in Rating)  is  begin
    if R0O0 = 0 then R00O := new ROO0( 1 .. 100 ); end if;
    if R0O0 + 1 > R00O.all'length then
    declare R000 : R0OO; begin R000 := new
    ROO0( 1 .. R0O0 + 100 ); R000.all( 1 .. R0O0 ) :=
    R00O.all( 1 .. R0O0 ); RO00( R00O ); R00O :=
    R000; end; end if; R0O0 := R0O0 + 1;
    R00O( R0O0 ).lll1 := citizen; R00O( R0O0 ).ll1l := badness; end
    Rate;

   procedure  reset is
   begin
      null;
   end reset;

end POP;

Steve
(The Duck)


>
> You cannot change this specification in any way other than to insert
> the appropriate type for ID;
> As you can see this is supposed to be a database package, it should not
> however do any input or output to the screent as the GUI is being
> designed by someone else.
>
> Rate is supposed to enter a citizen with his/her ID (integer) and their
> badness (integer) into the database.
> Associate  is used to tell the database two citizens are associated to
> be in the same group.
> Most_Dangerous is supposed to return the citizen with the highest
> badness rating. This function can do anything if the database is empty.
> Next_Member reports a previously unreported member of the group to
> which the most dangerous citizen belongs. This function can do anything
> if the there are no more unreported members.
> More_In_Group which is true exactly when there are unreported members
> of the group to which the most recently reported most dangerous citizen
> belongs. This function can do anything if there is no previous call to
> Most_Dangerous.
> The procedure rest resets the database to its original state.
>
> There will be no more than 1 million citizens entered. Updates should
> be optimised at the expense of queries. Do not worry too much about
> error handling.
>
> The program is supposed to be compiled on gnat. I require both the code
> and a compiled file.
>
> Again, if anyone is interested I'm willing to pay for your services.
> 





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

* Re: Help needed for ada package
  2005-07-25 23:33 ` Jeffrey Carter
@ 2005-07-26 17:29   ` Pascal Obry
  2005-07-26 19:03     ` Ed Falis
                       ` (2 more replies)
  0 siblings, 3 replies; 48+ messages in thread
From: Pascal Obry @ 2005-07-26 17:29 UTC (permalink / raw)



Jeffrey Carter <spam@spam.com> writes:

> Sounds good. I could do it for only $20 million, cash, in new $100 bills.

And me for only $15 million :)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Help needed for ada package
       [not found] <1122372224.124606.271380@f14g2000cwb.googlegroups.com>
@ 2005-07-26 17:31 ` tmoran
  0 siblings, 0 replies; 48+ messages in thread
From: tmoran @ 2005-07-26 17:31 UTC (permalink / raw)


  If you are a humanities major just trying to pass a required science
course, and just want something to barely "get by", forget priority queues
and databases and just use arrays.  If there aren't many citizens that
will work fine in both speed and storage.  If type ID is (<>); is for
instance "range 1 ..  100" just declare your arrays with ID as their
subscripts.  If ID is too big (eg, Integer), you can have a separate
lookup list to translate between ID and a (small) subscript value.
Even the "find all the associates of all the associates of ... of all
the associates of X can be done with a simple recursion and a check-off
list of citizens already looked at.
  In general, sitting back and asking "what information is required here?"
is a better start than "which of these complicated tools that I don't
really understand all that well, should I use?".  OTOH, be aware that more
than one dot-com company started with a simple implementation cooked up in
a dorm room that turned out not to scale up.



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

* Re: Help needed for ada package
  2005-07-26 17:29   ` Pascal Obry
@ 2005-07-26 19:03     ` Ed Falis
  2005-07-26 19:05       ` Pascal Obry
  2005-07-26 22:20     ` Jeffrey Carter
  2005-08-01  5:37     ` Dave Thompson
  2 siblings, 1 reply; 48+ messages in thread
From: Ed Falis @ 2005-07-26 19:03 UTC (permalink / raw)


On Tue, 26 Jul 2005 13:29:34 -0400, Pascal Obry <pascal@obry.net> wrote:

> And me for only $15 million :)

Euros?




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

* Re: Help needed for ada package
  2005-07-26 19:03     ` Ed Falis
@ 2005-07-26 19:05       ` Pascal Obry
  0 siblings, 0 replies; 48+ messages in thread
From: Pascal Obry @ 2005-07-26 19:05 UTC (permalink / raw)



"Ed Falis" <falis@verizon.net> writes:

> On Tue, 26 Jul 2005 13:29:34 -0400, Pascal Obry <pascal@obry.net> wrote:
> 
> > And me for only $15 million :)
> 
> Euros?

No $15 million is fine, but I'm ok for 15 million euros of course :)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Help needed for ada package
  2005-07-26 17:29   ` Pascal Obry
  2005-07-26 19:03     ` Ed Falis
@ 2005-07-26 22:20     ` Jeffrey Carter
  2005-07-27  9:07       ` Georg Bauhaus
  2005-08-01  5:37     ` Dave Thompson
  2 siblings, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2005-07-26 22:20 UTC (permalink / raw)


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

Pascal Obry wrote:
> 
> And me for only $15 million :)

Great, bidding war. Don't listen to Pascal, he won't deliver the quality 
you'll get from me.

OK, $14.9 million, but that's my final offer.

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

begin:vcard
fn:Jeffrey Carter
n:;Jeffrey Carter
email;internet:jeffrey_r_carter-nr [commercial-at] raytheon [period | full stop] com
x-mozilla-html:FALSE
version:2.1
end:vcard


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

* Re: Help needed for ada package
  2005-07-26 22:20     ` Jeffrey Carter
@ 2005-07-27  9:07       ` Georg Bauhaus
  0 siblings, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-07-27  9:07 UTC (permalink / raw)


Jeffrey Carter wrote:
> Pascal Obry wrote:
> 
>>
>> And me for only $15 million :)
> 
> 
> Great, bidding war. Don't listen to Pascal, he won't deliver the quality 
> you'll get from me.
> 
> OK, $14.9 million, but that's my final offer.


It's cheaper to buy in Europe,

http://www.ecb.int/stats/exchange/eurofxref/html/eurofxref-graph-usd.en.html



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

* Re: Help needed for ada package
       [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
@ 2005-07-27 17:13     ` Martin Krischik
  2005-07-27 18:03     ` Simon Wright
  2005-07-28  2:27     ` Steve
  2 siblings, 0 replies; 48+ messages in thread
From: Martin Krischik @ 2005-07-27 17:13 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:

>         type Society_Ptr is access all Society;
> 
>         Pointer : Society_Ptr;

Are you sure you need a pointer.  Most Ada compilers won't have a problem
creating the even a large array in static memory:

http://en.wikibooks.org/wiki/Programming:Ada:Types:array

Do you really need "access all"

http://en.wikibooks.org/wiki/Programming:Ada:Types:access#Access_vs._access_all

And last not least: there is no "new" to be seen anywhere:

http://en.wikibooks.org/wiki/Programming:Ada:Types:access#Creating_object_in_a_storage_pool

Martin

-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

* Re: Help needed for ada package
       [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
  2005-07-27 17:13     ` Martin Krischik
@ 2005-07-27 18:03     ` Simon Wright
  2005-07-28  0:58       ` Jeffrey Carter
  2005-07-28  2:27     ` Steve
  2 siblings, 1 reply; 48+ messages in thread
From: Simon Wright @ 2005-07-27 18:03 UTC (permalink / raw)


You could make Individual.Associate a packed array (1 .. 1_000_000) of
Boolean, set True if there's an Association .. though since
Association is symmetric as far as I can tell it might be better to
have a separate two-dimensional array for this.

I take it that ID is range 1 .. 1_000_000? if so you should index
Society by ID.

Why do you have pointers? you could just have an array of individuals.

Names are very important. "Pointer" is a very unhelpful name for the
concept you have in mind!

  type Individuals is array (ID) of Indivuals;
  Society : Individuals;

How are you going to know whether a given Individual exists? (has been
Rated, I think?)

--S



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

* Re: Help needed for ada package
  2005-07-27 18:03     ` Simon Wright
@ 2005-07-28  0:58       ` Jeffrey Carter
  2005-07-28  1:53         ` tmoran
  0 siblings, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2005-07-28  0:58 UTC (permalink / raw)


Simon Wright wrote:
> You could make Individual.Associate a packed array (1 .. 1_000_000) of
> Boolean, set True if there's an Association .. though since
> Association is symmetric as far as I can tell it might be better to
> have a separate two-dimensional array for this.

I'd probably use PragmARC.Skip_List_Unbounded for the collection of 
rated innocent victims (appox O(log N) for insertion and lookup), each 
having a list of associates. Then finding the highest rated is O(1), and 
visiting each of her associates would be approx O(log N).

-- 
Jeff Carter
"Why don't you bore a hole in yourself and let the sap run out?"
Horse Feathers
49



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

* Re: Help needed for ada package
  2005-07-28  0:58       ` Jeffrey Carter
@ 2005-07-28  1:53         ` tmoran
  2005-07-28 16:21           ` Jeffrey Carter
  0 siblings, 1 reply; 48+ messages in thread
From: tmoran @ 2005-07-28  1:53 UTC (permalink / raw)


> visiting each of her associates would be approx O(log N).
  And visiting all the associates of each of those ...
IIRC Warshall's algorithm for transitive closure is O(n**3).
Is there a faster way?



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

* Re: Help needed for ada package
       [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
  2005-07-27 17:13     ` Martin Krischik
  2005-07-27 18:03     ` Simon Wright
@ 2005-07-28  2:27     ` Steve
       [not found]       ` <1122547648.069514.63520@g14g2000cwa.googlegroups.com>
  2 siblings, 1 reply; 48+ messages in thread
From: Steve @ 2005-07-28  2:27 UTC (permalink / raw)


<strictly_mk@hotmail.com> wrote in message 
news:1122475184.849564.159870@g44g2000cwa.googlegroups.com...
> With the code kindly posted by Steve and with the advice some of you
> here gave me I have attempted this thing again and this is the code I
> have 'written'/'modified'. I've simplified it somewhat since I am
> supposed to show the concept of the procedures and functions working
> regardless if they fail after a certain amount of time.
>

Now that you're asking for help, and not for someone to do it for you, as 
you can see, you get a lot more positive response.

> package body POP is
>
> type Individual is
> record
> Person : ID;
> Danger : Rating;
> Associate : ID;
> Reported : Boolean;
> end record;
>
> type Society is array( 1 .. 1000000 ) of Individual;
>
> type Society_Ptr is access all Society;
>
> Pointer : Society_Ptr;
> Counter : Natrual := 0;
>

If the array is going to be fixed in size, why not just use:

  type Society is array( 1 .. 1000000 ) of Individual;

  Society_Buffer : Society;

  In my original response I used a pointer because I dynamically allocated 
an array to store individuals.  When the array became full, I dynamically 
allocated a new larger array, copied the values from the original array to 
the new larger array and then deallocated the original array.  It is 
certainly simpler to just go with a fixed maximum size.

> procedure Rate (Citizen : in ID; Badness : in Rating) is
> begin
> Counter := Counter + 1;
> Pointer( Counter ).Person := Citizen;
> Pointer( Counter ).Rating := Badness;
> Pointer( Counter ).Associate := null;
> Pointer( Counter ).Reported := false;
> end;
> end Rate;
>

  Just a note: One of the features I really like about Ada is the ability to 
do record assignments, so this Rate function could be:

  Counter := Counter + 1;
  Pointer( Counter ) := ( Person => Citizen, Rating => Badness, Associate => 
null, Reported => False );


> procedure Associate (Citizen_1, Citizen_2 : in ID) is
>
> I : Integer
>
> for I in 0..Counter loop
> if Pointer( I ).Citizen = Citizen_1
> then
> Pointer( I ).Associate := Citizen_2;
> end if;
> end Associate;
>
> --query functions
> function Most_Dangerous return ID is
>
> MD_Counter : Integer := 1;
>
> I : Integer
>
> for I in 0..Counter loop
> if Society(I).Danger < Society(MD_Counter).Danger then
> if Society(MD_Counter).Reported = false then
> begin
> Most_Dangerous_Pointer := MD_Counter;
> MD_Counter := MD_Counter + 1;
> end;
> else
> MD_Counter := MD_Counter + 1;
> end if;
> else
> MD_Counter := MD_Counter + 1;
> end if;
> end loop;
>
> begin
> return Pointer(Most_Dangerous_Pointer).Citizen;
> Pointer(Most_Dangerous_Pointer).Reported := true;
> end;
>
> end Most_Dangerous;
>
> I've put all the required information into an array of records. But the
> problem is I realised that if a citizen has more than one associate my
> code won't work. (If the code were to compile) As it stands it would
> logically work if each person only had one associate. I remember an old
> project using code similar to Associate : Associates.Bag within the
> record instances. An I was wondering if anyone knows how this package
> might look like. This way I could put Associate, Next_Member and
> More_In_Group in that package as well. I think this is what the marker
> is looking for as I think I'm supposed to demonstrate my program being
> modular. Any comments?
>

One way to handle the "associates" is to create an association code for each 
individual.  When two citizens are associated, make the id's of the 
associates the same.

You might, for example start out with an association id of 0 indicating no 
association.  When the Associate procedure is called, find the location of 
each of the citizens and handle each of the cases:
  If both associates have no association, create a new association id, and 
assign it to both.
  If just one of the associates has a non-zero association id, assign it to 
the other.
  If both of the associates have a non-zero association id (ie: A and B), 
then change the association ID of all citizens that are currently B to A.

I am assuming that:
  if A associated with B and B associated with C it is implied that A 
associated with C.

I hope this helps,
Steve
(The Duck)





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

* Re: Help needed for ada package
  2005-07-28  1:53         ` tmoran
@ 2005-07-28 16:21           ` Jeffrey Carter
  0 siblings, 0 replies; 48+ messages in thread
From: Jeffrey Carter @ 2005-07-28 16:21 UTC (permalink / raw)


tmoran@acm.org wrote:
> 
>   And visiting all the associates of each of those ...
> IIRC Warshall's algorithm for transitive closure is O(n**3).
> Is there a faster way?

I thought the requirement was only to visit all the associates of the 
highest rated individual. If you have to visit associates of associates 
of associates of ... then it becomes a little more time intensive.

-- 
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] 48+ messages in thread

* Re: Help needed for ada package
       [not found]       ` <1122547648.069514.63520@g14g2000cwa.googlegroups.com>
@ 2005-07-28 18:33         ` Ludovic Brenta
  2005-07-28 19:51           ` tmoran
       [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
  2005-07-29  1:57         ` Steve
  1 sibling, 2 replies; 48+ messages in thread
From: Ludovic Brenta @ 2005-07-28 18:33 UTC (permalink / raw)


Whoa, everyone seems to be going over the top, I think the solution
can be much simpler.

generic
    type ID is (<>); --some discrete type to be put here
package POP is
   --update database
  type Rating is new Integer range 0..255;
  procedure Rate (Citizen : in ID;
                  Badness : in Rating);
  procedure Associate (Citizen_1, Citizen_2 : in ID);
  --query the database
  function Most_Dangerous return ID;
  function Next_Member return ID;
  function More_In_Group return Boolean;
  --administrative
  procedure reset;
end POP;


Since the type ID is discrete, why not just use that as the array index type?

package body POP is
   Society : array (ID) of Rating := (others => Rating'First);
   Associacion : array (ID, ID) of Boolean := (others => others => False));
   pragma Pack (Association);

   Last_Reported : ID := ID'First;

   procedure Rate (Citizen : in ID;
                   Badness : in Rating) is
   begin
      Society (Citizen) := Rating;
   end Rate;

   procedure Associate (Citizen_1, Citizen_2 : in ID) is
   begin
      Association (Citizen_1, Citizen_2) := True;
   end Associate;

   function Most_Dagerous return ID is
      Result : ID := ID'First;
   begin
      for J in Society'Range loop
         if Society (J) > Result then
            Result := J;
         end if;
      end loop;
      return Result;
   end Most_Dangerous;


   function Next_Member return ID is
      J : constant ID := Most_Dangerous;
   begin
      if Last_Reported = ID'First then
         Last_Reported := J;
      end if;
      for K in ID'Succ (Last_Reported) .. Association'Last (2) loop
         if Association (J, K) then
            Last_Reported := K;
            exit;
         end loop;
      end loop;
      return Last_Reported;
   end Next_Member;


   function More_In_Group return Boolean is    
      J : constant ID := Most_Dangerous;
      Result : Boolean := False;
   begin
      for K in ID'Succ (Last_Reported) .. Association'Last (2) loop
         if Association (J, K) then
            Result := True;
            exit;
         end loop;
      end loop;
      return Result;
   end More_In_Group;


   procedure Reset is
   begin
      Society := (others => Rating'First);
      Association := (others => others => False));
      Last_Reported := ID'First;
   end Reset;
end POP;


Of course, the above solution is outrageously inefficient, both
memory- and CPU-wise.  Optimisations are left as an exercise to the
reader.

-- 
Ludovic Brenta.




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

* Re: Help needed for ada package
  2005-07-28 18:33         ` Ludovic Brenta
@ 2005-07-28 19:51           ` tmoran
       [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
  1 sibling, 0 replies; 48+ messages in thread
From: tmoran @ 2005-07-28 19:51 UTC (permalink / raw)


Nice and clean but:

Most_Dangerous = 10
Last_Reported = 20
Citizens 5 and 6 are associated.
then re-rate Citizen 5 as even more dangerous than 10.
Citizen 6 will not be noticed by Next_Member or More_In_Group.

Associate as written is not symmetric - is that what's wanted?

association is not transitive - is that what's wanted?

I would also change type Rating to Rating_Levels and array Society to
Rating.  Then "if Rating(J) > " reads better than "if Society(J) > ".

I notice a couple of typos, but the compiler will point them out.



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

* Re: Help needed for ada package
       [not found]       ` <1122547648.069514.63520@g14g2000cwa.googlegroups.com>
  2005-07-28 18:33         ` Ludovic Brenta
@ 2005-07-29  1:57         ` Steve
       [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
  1 sibling, 1 reply; 48+ messages in thread
From: Steve @ 2005-07-29  1:57 UTC (permalink / raw)


<strictly_mk@hotmail.com> wrote in message 
news:1122547648.069514.63520@g14g2000cwa.googlegroups.com...
> Thank you for all the suggestions. Here is what I've done so far,
[snip]
>
> What I wanna ask is how can you reset an entire array? For
> More_In_Group I want to reset the Members_Array and use a similar loop
> used in Next_Member to rebuild it, this way the previous member looked
> up disappears and all I would need to do is check if there are elements
> still in the array to return true or false. Any suggestions?
>
In your original post you indiciated:
  "The procedure rest resets the database to its original state."

So, I think all you need to do is set your counts and indexes back to 0.

Steve
(The Duck)





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

* Re: Help needed for ada package
       [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
@ 2005-07-29  8:37             ` tmoran
  2005-07-30  1:44             ` Steve
  1 sibling, 0 replies; 48+ messages in thread
From: tmoran @ 2005-07-29  8:37 UTC (permalink / raw)


>   type Association_Matrix is array (Id'First .. Id'Last) of
>Association_Vector;
>   pragma Pack(Association_Matrix);
>   --   1_000_000 rows of 125_000 bytes is 125_000_000_000 bytes
>   --   very fat, 125GB

  Remember that a symmetric array A(1 .. N, 1 .. N) can be stored in half
the space as a vector V(1 .. (N*(N+1))/2), where A(i,j) is at
V((max(i,j)*(max(i,j)-1))/2+min(i,j))



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

* Re: Help needed for ada package
       [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
  2005-07-29  8:37             ` tmoran
@ 2005-07-30  1:44             ` Steve
  1 sibling, 0 replies; 48+ messages in thread
From: Steve @ 2005-07-30  1:44 UTC (permalink / raw)


"Dennis Lee Bieber" <wlfraed@ix.netcom.com> wrote in message 
news:uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com...
> On Thu, 28 Jul 2005 20:33:32 +0200, Ludovic Brenta
> <ludovic.brenta@tiscali.be> declaimed the following in comp.lang.ada:
>
>
>>
>> Since the type ID is discrete, why not just use that as the array index 
>> type?
>>
> That's the approach I took, though some things aren't quite as
> clean (I used explicit ranges... should have tried compiling with just
> the type).
>> Of course, the above solution is outrageously inefficient, both
>> memory- and CPU-wise.  Optimisations are left as an exercise to the
>> reader.
>
> Tell me about it -- for the 1000000 population, I estimated over
> 100GB needed for the association matrix alone, even packing 1-bit
> booleans. I then did version 2, using "Steve's" suggestion of encoding
> the group identifier into the population data itself... associate() went
> from two lines to a page, but half the declarations disappear.
>
> I will not be posting that version as it is too close to being
> directly usable (I didn't write a test suite, so couldn't run it, but it
> did compile cleanly).
>

Perhaps I'm a little naive, but I really don't understand why you need to 
keep any more than:

  type Persson is
    record
      Citizen_Id : ID;
      Badness    : Rating;
      Group_Id  : Natural;
    end record;

  type Population is array( 1 .. 1_000_000) of Person;

  Society     : Population;
  Next_In    : Positive; -- Add new elements here
  Next_Out : Positive; -- Retrieve next from current group here
  Baddest    : Positive; -- Index to baddest entry
  Current_Group_Id : Natural;

You do wind up scanning the list to do just about anything, but speed was 
not a requirement.

Steve
(The Duck)


[snip]
>
>
> -- 
> > ============================================================== <
> >   wlfraed@ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
> >      wulfraed@dm.net     |       Bestiaria Support Staff       <
> > ============================================================== <
> >           Home Page: <http://www.dm.net/~wulfraed/>            <
> >        Overflow Page: <http://wlfraed.home.netcom.com/>        < 





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

* Re: Help needed for ada package
  2005-07-26 17:29   ` Pascal Obry
  2005-07-26 19:03     ` Ed Falis
  2005-07-26 22:20     ` Jeffrey Carter
@ 2005-08-01  5:37     ` Dave Thompson
  2005-08-01 12:37       ` Adrien Plisson
  2 siblings, 1 reply; 48+ messages in thread
From: Dave Thompson @ 2005-08-01  5:37 UTC (permalink / raw)


On 26 Jul 2005 19:29:34 +0200, Pascal Obry <pascal@obry.net> wrote:

> 
> Jeffrey Carter <spam@spam.com> writes:
> 
> > Sounds good. I could do it for only $20 million, cash, in new $100 bills.
> 
> And me for only $15 million :)
> 
comp.lang.c has a consensus that "bidding" on homework assignments can
only go up, not down.  I think they got this one right. 

Aside: _Are_ there any new $100 bills? I haven't seen any since the
redesigned $20's started, in what-was-it 1997 or so, and I heard the
Treasury (or Fed?) wasn't going to do new $100s since this
denomination is believed useful primarily to criminals. Of course they
get little enough circulation you could certainly ask for "like-new"
or "good condition". (I am assuming $=USD, not CA or AU or such.)
- David.Thompson1 at worldnet.att.net



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

* Re: Help needed for ada package
  2005-08-01  5:37     ` Dave Thompson
@ 2005-08-01 12:37       ` Adrien Plisson
  0 siblings, 0 replies; 48+ messages in thread
From: Adrien Plisson @ 2005-08-01 12:37 UTC (permalink / raw)


Dave Thompson wrote:
> (I am assuming $=USD, not CA or AU or such.)

all bidders forgot to specify what kind of dollars they were using for 
their offer.

the OP may eventually afford ZWD 15_000_000 (Zimbabwe Dollars), but 
the bidders may have requested KYD 15_000_000 (Cayman Islands Dollars)...

-- 
rien



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

* Re: Help needed for ada package
       [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
@ 2005-08-02 11:37             ` Adrien Plisson
  2005-08-02 12:05             ` Georg Bauhaus
                               ` (2 subsequent siblings)
  3 siblings, 0 replies; 48+ messages in thread
From: Adrien Plisson @ 2005-08-02 11:37 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> open_resit.adb:63:05: argument of type conversion must be single
> expression
> open_resit.adb:63:17: illegal operand for array conversion

you declare:
type Associates is array ( Population_Range , Population_Range ) of
Boolean;

this declares a type, not a variable. you have to declare a variable 
of this type to use this data structure.

> ID is defined in the specification under generic as a long_integer. 

ID is NOT generic:
- it does not appear in a generic clause to this package,
- you convert variables of type ID explicitely to Long_Integer 
everywhere in this package, preventing a truly generic definition of ID.

(additionnaly, the array to store citizen association is indexed by 
Population_Range, not by ID, which leads to a compilation error in the 
procedure Associate)

and what about Rating ? it seems not defined anywhere...


-- 
rien



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

* Re: Help needed for ada package
       [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
  2005-08-02 11:37             ` Adrien Plisson
@ 2005-08-02 12:05             ` Georg Bauhaus
       [not found]               ` <1122986293.760710.320180@g44g2000cwa.googlegroups.com>
  2005-08-02 16:52             ` Jeffrey Carter
       [not found]             ` <o04ve11odsjs756915g5eonn0g1guopih2@4ax.com>
  3 siblings, 1 reply; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-02 12:05 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> Thanks for all the help, I've actually done most of it now but I need
> help on one last thing. I'm sure gnat doesn't like me and I'm getting
> these error messages regarding the Associates array, I've tried next to
> everything and I'm stuck. Here is to code and the compiler output.
> 

> subtype Population_Range is Long_Integer range 1..1000000;

> ID is defined in the specification under generic as a long_integer. Can
> anyone help?

(I'd suggest using the ID generic formal in the definition of
Population_Range then.)

Associates is a type actually, but is used as if it were variable.



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

* Re: Help needed for ada package
       [not found]               ` <1122986293.760710.320180@g44g2000cwa.googlegroups.com>
@ 2005-08-02 13:19                 ` Adrien Plisson
  2005-08-02 14:26                 ` Georg Bauhaus
  1 sibling, 0 replies; 48+ messages in thread
From: Adrien Plisson @ 2005-08-02 13:19 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> When you mean Associates is a type, can I just declare a variable like
> this
> 
> Associates_Variable : Associates; and use that within the rest of the
> code?

yes. you can even write:

Associates : array ( Population_Range , Population_Range ) of Boolean;

though it may comes in the way later if you want to extend this 
package (to manage more than one population for example).

-- 
rien



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

* Re: Help needed for ada package
       [not found]               ` <1122986293.760710.320180@g44g2000cwa.googlegroups.com>
  2005-08-02 13:19                 ` Adrien Plisson
@ 2005-08-02 14:26                 ` Georg Bauhaus
       [not found]                   ` <1122995870.689997.66000@g44g2000cwa.googlegroups.com>
  1 sibling, 1 reply; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-02 14:26 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:

> I'm a little confused with the generic part though - i don't know how
> to manipulate this bit.

generic
   type T is {something};
package Pack is

   -- refer to T is if it were a known type.
   -- What you know about the type here is
   -- expressed in {something}. For example,

   -- when {something} is replaced by "range <>"
   -- then you can use T inside Pack as if it were a
   -- signed integer type. When you make an instance
   -- of Pack, use some subtype of a signed integer
   -- type, like Natural, etc..




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

* Re: Help needed for ada package
       [not found]                   ` <1122995870.689997.66000@g44g2000cwa.googlegroups.com>
@ 2005-08-02 15:38                     ` Georg Bauhaus
       [not found]                       ` <1122997736.667017.104140@o13g2000cwo.googlegroups.com>
  0 siblings, 1 reply; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-02 15:38 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> sorry I dont understand that completely, can you show me what my code
> should look like?
> 

I guess you are referring to the generic Pack?
I had been assuming that ID is a generic formal type, like in

generic
	type ID is new Long_Integer;

package PoP is

Is that your choice, or have they given you this piece of the
program text?




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

* Re: Help needed for ada package
       [not found]                       ` <1122997736.667017.104140@o13g2000cwo.googlegroups.com>
@ 2005-08-02 16:37                         ` Georg Bauhaus
  0 siblings, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-02 16:37 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> is there a more appropriate type that
> wont upset the rest of the program?

Use one of Ada's formal types. That is, specify what
the generic needs as a type using the syntax for formal
types. Examples

generic
  type T is range <>;
package Pack ...

In this case the formal type T says, if you want to make
an instance of this generic package, you have to provide
a signed integer type as the (actual) type to be used in
the created instance, as in

  package Foo is new Pack (T => Integer);

Integer is a signed integer type, as are Natural, or
Long_Integer. When you instantiate Pack, you can choose the type
to be used. When you write the generic package, you only
specify some assumptions about the possible types.
In this case, "range <>" specifies "some signed integer type".

Given these possible assumptions about T, you can use
T in expressions, without knowing what T is going to be in
some instance of the generic package. Like T'First (the first of
the values in T's range). You can add values of T because
T denotes some integer type, no matter which one actually,
later.

Another example is 

generic
  type T is (<>);
package Pack2 ...

In this case formal type T says, if you want to make
an instance of this generic package, you have to provide
a discrete type as the (actual) type to be used in
the created instance. Discrete types are either integer
types or enumeration types. Just no real types.

So if you had, somewhere

  type Family is (Jack, Jakub, Florentina, Marge, Bart);

i.e. an enumeration type, you could say

  package Foo2 is new Pack2 (T => Family);

Inside Pack2 (the generic) you can use T just like you
use any enumeration type. For example, you can say T'First,
but you cannot add values, because this doesn't work for
enumeration types. When you write the package, you know you
can assume T is denoting an enumeration type, but not which one.
Because that is decided when someone, possibly you, instantiate
Pack2.

Last, when you have

generic
  type ID is new Long_Integer;
package PoP ...

the choice of types to be used when instantiating is pretty fixed.
Only types derived from Long_Integer (includes Long_Integer) or
subtypes thereof can be filled in when you write

  package My_PoP_Instance is new PoP(ID => ...);




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

* Re: Help needed for ada package
       [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
  2005-08-02 11:37             ` Adrien Plisson
  2005-08-02 12:05             ` Georg Bauhaus
@ 2005-08-02 16:52             ` Jeffrey Carter
       [not found]             ` <o04ve11odsjs756915g5eonn0g1guopih2@4ax.com>
  3 siblings, 0 replies; 48+ messages in thread
From: Jeffrey Carter @ 2005-08-02 16:52 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
>                 if Associates( Most_Dangerous_Person , I ) = True and
>                    Society(I).Reported = False then

Someone needs to understand the concept of Booleans.

-- 
Jeff Carter
"If you don't get the President of the United States on that
phone, ... you're going to have to answer to the Coca-Cola
Company."
Dr. Strangelove
32



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

* Re: Help needed for ada package
       [not found]             ` <o04ve11odsjs756915g5eonn0g1guopih2@4ax.com>
@ 2005-08-02 23:21               ` tmoran
       [not found]               ` <1123069124.562944.246730@o13g2000cwo.googlegroups.com>
  1 sibling, 0 replies; 48+ messages in thread
From: tmoran @ 2005-08-02 23:21 UTC (permalink / raw)


> > subtype Population_Range is Long_Integer range 1..1000000;
> >
>         Just curious... Why "long_integer"? I though most all GNAT
> implementations used 32-bit integer, and you only need 21-bits to handle
> +/- 1_000_000
  If the range is supposed to be 1 .. 1 million then say so:
type Population_Range is range 1..1_000_000;
  Relying on guesses about what compiler might be used and what it might
do is C-thought. :(



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

* Re: Help needed for ada package
       [not found]               ` <1123069124.562944.246730@o13g2000cwo.googlegroups.com>
@ 2005-08-03 12:08                 ` Georg Bauhaus
  2005-08-03 16:13                   ` Jeffrey Carter
                                     ` (2 more replies)
       [not found]                 ` <n0o1f1lqsbi23bt7b2li6oc85r7pgfn9d5@4ax.com>
  1 sibling, 3 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-03 12:08 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> Thank you for pointing that out, I changed Long_Integer back to integer
> and Associates now works with ID. BUT..
> Sorry everyone but I was just told that there is a mistake in the
> specification and ID is supposed to read like this type ID is (<>);
> Now all the errors I get in to compiler is this
> 
> open_resit.adb:91:50: expected type "ID" defined at open_resit.ads:2
> open_resit.adb:91:50: found type universal integer
> 
> I still am not sure how to use generics properly, what am I supposed to
> write and where do I put it? I'm hoping this is the last sort of
> problem I have to fix so this thing can finaly compile.

You have

generic
  type ID is (<>);
package PoP is ...

Some of your subprograms inside the package take ID parameters.

A discrete type (that's what "(<>)" implies) lets you base array type
definitions inside the package on properties of the generic discrete
type ID, like so:

  type Some_Array_Type is array (ID'range) of Some_Type;

This is the basically same as

   type Some_Array_Type is
     array(ID'first .. ID'last) of Some_Type;

'Range, 'first, and 'last are properties available with every discrete
type.


Likewise, you can write loops,

   for k in ID'range loop
      ...
   end loop;

or

   some_variable: Some_Array_Type;
   ...
   for k in some_variable'first .. some_variable'last loop
      -- use some_variable(k) here
   end loop;

BTW, there is no need to declare for-loop variables, these
are "automatically" declared.

So just give up thinking in terms of whatever Integer type you
have in mind. Your job, IIUC, is to write code inside a generic
that is parameterized by the type "ID". This type is a discrete
type, this is all you know, and it is all you need to know.



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

* Re: Help needed for ada package
  2005-08-03 12:08                 ` Georg Bauhaus
@ 2005-08-03 16:13                   ` Jeffrey Carter
  2005-08-03 17:57                     ` Georg Bauhaus
  2005-08-03 16:48                   ` Martin Dowie
       [not found]                   ` <1123084562.854161.299550@g44g2000cwa.googlegroups.com>
  2 siblings, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2005-08-03 16:13 UTC (permalink / raw)


Georg Bauhaus wrote:
> 
>  type Some_Array_Type is array (ID'range) of Some_Type;

This is the same as

type Some_Array_Type is array (ID) of Some_Type;

Attributes are fine, but let's not overuse them.

-- 
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] 48+ messages in thread

* Re: Help needed for ada package
  2005-08-03 12:08                 ` Georg Bauhaus
  2005-08-03 16:13                   ` Jeffrey Carter
@ 2005-08-03 16:48                   ` Martin Dowie
       [not found]                   ` <1123084562.854161.299550@g44g2000cwa.googlegroups.com>
  2 siblings, 0 replies; 48+ messages in thread
From: Martin Dowie @ 2005-08-03 16:48 UTC (permalink / raw)


Georg Bauhaus wrote:
> Likewise, you can write loops,
>
>    for k in ID'range loop
>       ...
>    end loop;
>
> or
>
>    some_variable: Some_Array_Type;
>    ...
>    for k in some_variable'first .. some_variable'last loop
>       -- use some_variable(k) here
>    end loop;

but preferably:

for k in some_variable'range loop
   -- use some_variable (k) here
end loop;

The compiler will deduce there are no runtime checks required with this
construct but I've seen plenty compilers that will insert checks in the
other forms (even though we can see they aren't really needed).

Cheers

-- Martin





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

* Re: Help needed for ada package
  2005-08-03 16:13                   ` Jeffrey Carter
@ 2005-08-03 17:57                     ` Georg Bauhaus
  0 siblings, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-03 17:57 UTC (permalink / raw)


Jeffrey Carter wrote:

> type Some_Array_Type is array (ID) of Some_Type;
> 
> Attributes are fine, but let's not overuse them.

Right, I wasn't seeing the wood for the trees.


-- Georg 


 



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

* Re: Help needed for ada package
       [not found]                   ` <1123084562.854161.299550@g44g2000cwa.googlegroups.com>
@ 2005-08-03 17:58                     ` Georg Bauhaus
  0 siblings, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-03 17:58 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> Can I define the range of ID outside the specification? I am still
> getting the same error messages.

As Dennis has explained, this is done during instantiation.

> What is the range of ID in type Some_Array__Type is array (ID'range) of
> Some_Type; ?

It's ID'Range :-)





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

* Re: Help needed for ada package
       [not found]                   ` <1123090742.323338.311230@f14g2000cwb.googlegroups.com>
@ 2005-08-03 18:07                     ` Georg Bauhaus
  2005-08-03 20:18                     ` Simon Wright
  1 sibling, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-03 18:07 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> Actually I think I fixed the majority of them, here is the package
> body; FYI  type ID is (<>);
> 
> The only problem really now is that line 91 refers to the most
> dangerous function where it says Most_Dangerous_Person := 0;
> I think the compiler is complaining about 0 being passed off as an ID.

That's right, 0 is known to belong to a universal intege type,
but (<>) says discrete type. So you cannot assume there will be
a 0.

> Line 120 refers to the return 0; in the next_member function (again I
> think its to do with 0 not being an integer) (again, is there a way
> around this?)

I think so. If there is a most dangerous person
(i.e., at least one, in math speak I think)
then this person's ID should be the one to use in identifying the person?

Not sure why you assign a default value (?) to Most_Dangerous_Person?
(If you need a default value, some ID values are available
through ID's type attributes.)



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

* Re: Help needed for ada package
       [not found]                   ` <1123090742.323338.311230@f14g2000cwb.googlegroups.com>
  2005-08-03 18:07                     ` Georg Bauhaus
@ 2005-08-03 20:18                     ` Simon Wright
  2005-08-04  0:59                       ` Jeffrey Carter
  1 sibling, 1 reply; 48+ messages in thread
From: Simon Wright @ 2005-08-03 20:18 UTC (permalink / raw)


"strictly_mk@hotmail.com" <strictly_mk@hotmail.com> writes:

> Line 120 refers to the return 0; in the next_member function (again
> I think its to do with 0 not being an integer) (again, is there a
> way around this?)

You need to return the value of ID which means "not a valid ID". That
might be ID'First or ID'Last (your value of 0 implies 'First). But I
expect that your first Person would have an ID of 'First! Sounds like
there's a deep problem in the spec there?



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

* Re: Help needed for ada package
  2005-08-03 20:18                     ` Simon Wright
@ 2005-08-04  0:59                       ` Jeffrey Carter
  2005-08-04  5:42                         ` Simon Wright
  0 siblings, 1 reply; 48+ messages in thread
From: Jeffrey Carter @ 2005-08-04  0:59 UTC (permalink / raw)


Simon Wright wrote:
> 
> You need to return the value of ID which means "not a valid ID". That
> might be ID'First or ID'Last (your value of 0 implies 'First). But I
> expect that your first Person would have an ID of 'First! Sounds like
> there's a deep problem in the spec there?

IIRC, the spec states that anything may be returned if there's no valid 
value.

-- 
Jeff Carter
"I was hobbling along, minding my own business, all of a
sudden, up he comes, cures me! One minute I'm a leper with
a trade, next minute my livelihood's gone! Not so much as a
'by your leave!' You're cured, mate. Bloody do-gooder!"
Monty Python's Life of Brian
76



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

* Re: Help needed for ada package
  2005-08-04  0:59                       ` Jeffrey Carter
@ 2005-08-04  5:42                         ` Simon Wright
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Wright @ 2005-08-04  5:42 UTC (permalink / raw)


Jeffrey Carter <spam@spam.com> writes:

> Simon Wright wrote:
>> You need to return the value of ID which means "not a valid
>> ID". That
>> might be ID'First or ID'Last (your value of 0 implies 'First). But I
>> expect that your first Person would have an ID of 'First! Sounds like
>> there's a deep problem in the spec there?
>
> IIRC, the spec states that anything may be returned if there's no
> valid value.

Oh yes, I was forgetting this is an exercise ..



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

* Re: Help needed for ada package
       [not found]       ` <1123174747.107994.317580@o13g2000cwo.googlegroups.com>
@ 2005-08-04 16:27         ` Georg Bauhaus
  2005-08-04 20:14         ` Simon Wright
  1 sibling, 0 replies; 48+ messages in thread
From: Georg Bauhaus @ 2005-08-04 16:27 UTC (permalink / raw)


strictly_mk@hotmail.com wrote:
> I am using gnatmake but I dont know which switch/option to use. I cant
> see an appropriate one.
> 

no switches needed except -gnato if you want integer overflow
checking (as per Ada standard).

the generic package body that you have written cannot be
used alone to compile an executable. some other compilation
unit (source file) must have code that instantiates
your generic package and calls the subprograms. Have you been
given only the spec of the generic package, or is there
something else?




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

* Re: Help needed for ada package
       [not found]   ` <1123173235.773051.23360@z14g2000cwz.googlegroups.com>
@ 2005-08-04 16:50     ` Simon Clubley
       [not found]       ` <1123174747.107994.317580@o13g2000cwo.googlegroups.com>
  0 siblings, 1 reply; 48+ messages in thread
From: Simon Clubley @ 2005-08-04 16:50 UTC (permalink / raw)


In article <1123173235.773051.23360@z14g2000cwz.googlegroups.com>, "strictly_mk@hotmail.com" <strictly_mk@hotmail.com> writes:
> thank you for pointing that out, now I have one last question. The adb
> file will compile but I only get a .o file as an output. How do I make
> gnat output an executable instead?  (I know that if i execute the code
> as is I will not get anything) I just want to know so I can start
> testing.
> 

Are you using the gnatmake or gcc command to compile your code ?

It sounds like you are doing the latter, but you want the former. Ie, if
your main program is called mk_main.adb, you would issue the following
command:

	gnatmake mk_main.adb

Gnatmake will then compile and link files as required.

Type gnatmake by itself to see the list of available options.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP       
Microsoft: The Standard Oil Company of the 21st century



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

* Re: Help needed for ada package
       [not found]       ` <1123174747.107994.317580@o13g2000cwo.googlegroups.com>
  2005-08-04 16:27         ` Georg Bauhaus
@ 2005-08-04 20:14         ` Simon Wright
  1 sibling, 0 replies; 48+ messages in thread
From: Simon Wright @ 2005-08-04 20:14 UTC (permalink / raw)


"strictly_mk@hotmail.com" <strictly_mk@hotmail.com> writes:

> I am using gnatmake but I dont know which switch/option to use. I cant
> see an appropriate one.

You can't make an executable unless you have a main program. gnatmake
will build an executable if the source file you give it is capable of
being a main program (ie, is a parameterless procedure); otherwise it
won't.



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

end of thread, other threads:[~2005-08-04 20:14 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1122305318.728942.304120@f14g2000cwb.googlegroups.com>
2005-07-25 17:45 ` Help needed for ada package Marc A. Criley
2005-07-25 17:47 ` Simon Clubley
2005-07-25 18:21   ` Georg Bauhaus
2005-07-25 18:46 ` Frank J. Lhota
2005-07-25 19:26 ` tmoran
2005-07-25 22:12 ` Ludovic Brenta
2005-07-25 23:33 ` Jeffrey Carter
2005-07-26 17:29   ` Pascal Obry
2005-07-26 19:03     ` Ed Falis
2005-07-26 19:05       ` Pascal Obry
2005-07-26 22:20     ` Jeffrey Carter
2005-07-27  9:07       ` Georg Bauhaus
2005-08-01  5:37     ` Dave Thompson
2005-08-01 12:37       ` Adrien Plisson
2005-07-26  3:17 ` Steve
     [not found]   ` <1122475184.849564.159870@g44g2000cwa.googlegroups.com>
2005-07-27 17:13     ` Martin Krischik
2005-07-27 18:03     ` Simon Wright
2005-07-28  0:58       ` Jeffrey Carter
2005-07-28  1:53         ` tmoran
2005-07-28 16:21           ` Jeffrey Carter
2005-07-28  2:27     ` Steve
     [not found]       ` <1122547648.069514.63520@g14g2000cwa.googlegroups.com>
2005-07-28 18:33         ` Ludovic Brenta
2005-07-28 19:51           ` tmoran
     [not found]           ` <uaaje1d0l4tp1kjs18mkrgfmbkcir308bt@4ax.com>
2005-07-29  8:37             ` tmoran
2005-07-30  1:44             ` Steve
2005-07-29  1:57         ` Steve
     [not found]           ` <1122980923.842598.181310@g49g2000cwa.googlegroups.com>
2005-08-02 11:37             ` Adrien Plisson
2005-08-02 12:05             ` Georg Bauhaus
     [not found]               ` <1122986293.760710.320180@g44g2000cwa.googlegroups.com>
2005-08-02 13:19                 ` Adrien Plisson
2005-08-02 14:26                 ` Georg Bauhaus
     [not found]                   ` <1122995870.689997.66000@g44g2000cwa.googlegroups.com>
2005-08-02 15:38                     ` Georg Bauhaus
     [not found]                       ` <1122997736.667017.104140@o13g2000cwo.googlegroups.com>
2005-08-02 16:37                         ` Georg Bauhaus
2005-08-02 16:52             ` Jeffrey Carter
     [not found]             ` <o04ve11odsjs756915g5eonn0g1guopih2@4ax.com>
2005-08-02 23:21               ` tmoran
     [not found]               ` <1123069124.562944.246730@o13g2000cwo.googlegroups.com>
2005-08-03 12:08                 ` Georg Bauhaus
2005-08-03 16:13                   ` Jeffrey Carter
2005-08-03 17:57                     ` Georg Bauhaus
2005-08-03 16:48                   ` Martin Dowie
     [not found]                   ` <1123084562.854161.299550@g44g2000cwa.googlegroups.com>
2005-08-03 17:58                     ` Georg Bauhaus
     [not found]                 ` <n0o1f1lqsbi23bt7b2li6oc85r7pgfn9d5@4ax.com>
     [not found]                   ` <1123090742.323338.311230@f14g2000cwb.googlegroups.com>
2005-08-03 18:07                     ` Georg Bauhaus
2005-08-03 20:18                     ` Simon Wright
2005-08-04  0:59                       ` Jeffrey Carter
2005-08-04  5:42                         ` Simon Wright
     [not found]   ` <1123173235.773051.23360@z14g2000cwz.googlegroups.com>
2005-08-04 16:50     ` Simon Clubley
     [not found]       ` <1123174747.107994.317580@o13g2000cwo.googlegroups.com>
2005-08-04 16:27         ` Georg Bauhaus
2005-08-04 20:14         ` Simon Wright
     [not found] <1122320036.858648.242630@f14g2000cwb.googlegroups.com>
2005-07-26  0:47 ` tmoran
     [not found] <1122372224.124606.271380@f14g2000cwb.googlegroups.com>
2005-07-26 17:31 ` tmoran

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