comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: beginner array question
Date: Thu, 20 Nov 2003 17:40:14 GMT
Date: 2003-11-20T17:40:14+00:00	[thread overview]
Message-ID: <207vb.7124$sb4.1469@newsread2.news.pas.earthlink.net> (raw)
In-Reply-To: <92bfc3dd.0311200234.2b74b41f@posting.google.com>

lolo27 wrote:

> generic
>    ---------general parameters-----------
>    type Someting is(<>);
>    type something_array is Array (integer range<>) of Someting ;   
> 
> ---------------------------------------------------
> in the adb file i want to ask the following 
>  function is_final(current_state:Someting ;final:something_array )
 >  return boolean is
>    begin
>       if current_state in final'First..final'Last then
>          return true;
>       else
>          return false;
>       end if;  
>    end is_final;

There are a couple of problems here. "in" tests for subtype membership.
Final'First .. Final'Last (equivalent to Final'range) is a subtype of
Integer, because the index type of Something_Array is Integer. Within
the generic, Something is not an integer type, so this test should 
always return False.

Presumably you want to check if Current_State is equal to one of the
components of Final. To do that, you'll have to search Final. If Final
is sorted, you can use a binary search; otherwise, you'll have to use a
linear search.

Your construct indicates that you do not understand booleans. If you
could use the test you coded, you should have written

return Current_State in Final'range;

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail
03




      parent reply	other threads:[~2003-11-20 17:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-20 10:34 beginner array question lolo27
2003-11-20 12:00 ` Jeff C,
2003-11-20 12:03 ` David C. Hoos, Sr.
2003-11-20 17:40 ` Jeffrey Carter [this message]
replies disabled

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