* beginner array question
@ 2003-11-20 10:34 lolo27
2003-11-20 12:00 ` Jeff C,
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: lolo27 @ 2003-11-20 10:34 UTC (permalink / raw)
hi
i am writing a generic package
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;
----
how can i ask if current_state is in final
thanks a lot
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: beginner array question
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
2 siblings, 0 replies; 4+ messages in thread
From: Jeff C, @ 2003-11-20 12:00 UTC (permalink / raw)
"lolo27" <limor_ru@walla.co.il> wrote in message
news:92bfc3dd.0311200234.2b74b41f@posting.google.com...
> 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;
>
> ----
>
> how can i ask if current_state is in final
>
> thanks a lot
Not like this at all.. The "in" keyword is not an array search operator.
There is no single "search" this array for
a value keyword. You need to look through your array checking each value in
the array to see if it is
= to the current_state value. If you find it, return true. If you make it
out of the loop without finding it, return
false.
Since I am (perhaps incorrectly) assuming this is a homework related issue,
I did not post code..Hopefully (either way) the text based info is enough to
get you on the right track.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: beginner array question
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
2 siblings, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 2003-11-20 12:03 UTC (permalink / raw)
To: lolo27, comp.lang.ada
You need to do it like this:
function is_final(current_state:Something ;final:something_array) return boolean is
begin
for i in final'range loop
if current_state = final (i) then
return true;
end if;
end loop
return false;
end is_final;
----- Original Message -----
From: "lolo27" <limor_ru@walla.co.il>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: November 20, 2003 4:34 AM
Subject: beginner array question
> hi
> i am writing a generic package
> 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;
>
> ----
>
> how can i ask if current_state is in final
>
> thanks a lot
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: beginner array question
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
2 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Carter @ 2003-11-20 17:40 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-11-20 17:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox