* Ada code snippet help (array of arrays)
@ 2009-05-13 14:11 Vamp4L
2009-05-13 14:25 ` Georg Bauhaus
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Vamp4L @ 2009-05-13 14:11 UTC (permalink / raw)
Trying to figure out why my code doesn't work
This line in particular doesn't compile "if Theater(Seat)(reserved) =
F then" :
with Ada.Text_Io; use Ada.Text_Io;
procedure Ch4Ex22 is
package Int_Io is new Integer_Io(Integer);
use Int_Io;
package Boolean_Io is new Enumeration_Io(Boolean);
use Boolean_Io;
T: constant Boolean := True;
F: constant Boolean := False;
type Seatattributes is (Reserved, Balcony);
type SeatType is array(SeatAttributes) of Boolean;
type Theater is array (1..50) of SeatType;
A: Theater := (1=>(T,F),2..7=>(F,F),8=>(T,F),9..15=>(F,F),16=>
(T,F),
17..23=>(F,F),24=>(T,F),25..29=>(F,F),30..31=>(F,T),32=>(T,T),
33..49=>(F,T),50=>(T,T));
begin
for Seat in Theater'range loop
if Theater(Seat)(reserved) = F then
Put(Seat, 1); New_Line;
end if;
end loop;
end Ch4Ex22;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada code snippet help (array of arrays)
2009-05-13 14:11 Ada code snippet help (array of arrays) Vamp4L
@ 2009-05-13 14:25 ` Georg Bauhaus
2009-05-13 14:28 ` Vamp4L
2009-05-13 15:05 ` Jacob Sparre Andersen
2009-05-14 8:05 ` Egil Høvik
2 siblings, 1 reply; 7+ messages in thread
From: Georg Bauhaus @ 2009-05-13 14:25 UTC (permalink / raw)
Vamp4L schrieb:
> Trying to figure out why my code doesn't work
> This line in particular doesn't compile "if Theater(Seat)(reserved) =
> F then" :
>
> with Ada.Text_Io; use Ada.Text_Io;
> procedure Ch4Ex22 is
> package Int_Io is new Integer_Io(Integer);
> use Int_Io;
> package Boolean_Io is new Enumeration_Io(Boolean);
> use Boolean_Io;
>
> T: constant Boolean := True;
> F: constant Boolean := False;
> type Seatattributes is (Reserved, Balcony);
> type SeatType is array(SeatAttributes) of Boolean;
> type Theater is array (1..50) of SeatType;
> A: Theater := (1=>(T,F),2..7=>(F,F),8=>(T,F),9..15=>(F,F),16=>
> (T,F),
> 17..23=>(F,F),24=>(T,F),25..29=>(F,F),30..31=>(F,T),32=>(T,T),
> 33..49=>(F,T),50=>(T,T));
>
> begin
>
> for Seat in Theater'range loop
> if Theater(Seat)(reserved) = F then
"Theater" is the name of a type. I guess you meant
the array object A?
> Put(Seat, 1); New_Line;
> end if;
> end loop;
>
> end Ch4Ex22;
--
--
Georg Bauhaus
Y A Time Drain http://www.9toX.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada code snippet help (array of arrays)
2009-05-13 14:25 ` Georg Bauhaus
@ 2009-05-13 14:28 ` Vamp4L
0 siblings, 0 replies; 7+ messages in thread
From: Vamp4L @ 2009-05-13 14:28 UTC (permalink / raw)
Thanks, I figured it was something stupid :)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada code snippet help (array of arrays)
2009-05-13 14:11 Ada code snippet help (array of arrays) Vamp4L
2009-05-13 14:25 ` Georg Bauhaus
@ 2009-05-13 15:05 ` Jacob Sparre Andersen
2009-05-14 8:05 ` Egil Høvik
2 siblings, 0 replies; 7+ messages in thread
From: Jacob Sparre Andersen @ 2009-05-13 15:05 UTC (permalink / raw)
Vamp4L <vampiro4l@gmail.com> writes:
> F: constant Boolean := False;
> if Theater(Seat)(reserved) = F then
The common way to write this is:
if not Theater (Seat) (Reserved) then
Greetings,
Jacob
--
�What fun is it being "cool" if you can't wear a sombrero?�
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada code snippet help (array of arrays)
2009-05-13 14:11 Ada code snippet help (array of arrays) Vamp4L
2009-05-13 14:25 ` Georg Bauhaus
2009-05-13 15:05 ` Jacob Sparre Andersen
@ 2009-05-14 8:05 ` Egil Høvik
2009-05-14 15:16 ` Adam Beneschan
2 siblings, 1 reply; 7+ messages in thread
From: Egil Høvik @ 2009-05-14 8:05 UTC (permalink / raw)
On May 13, 4:11 pm, Vamp4L <vampir...@gmail.com> wrote:
> Trying to figure out why my code doesn't work
> This line in particular doesn't compile "if Theater(Seat)(reserved) =
> F then" :
>
> with Ada.Text_Io; use Ada.Text_Io;
> procedure Ch4Ex22 is
> package Int_Io is new Integer_Io(Integer);
> use Int_Io;
> package Boolean_Io is new Enumeration_Io(Boolean);
> use Boolean_Io;
>
> T: constant Boolean := True;
> F: constant Boolean := False;
No need to define your own constants... True and False are
already enumerated values (constants) of type Boolean.
> type Seatattributes is (Reserved, Balcony);
> type SeatType is array(SeatAttributes) of Boolean;
Attributes of a type are usually represented as a record:
type Seating is
record
Reserved : Boolean;
Balcony : Boolean;
end record;
> type Theater is array (1..50) of SeatType;
> A: Theater := (1=>(T,F),2..7=>(F,F),8=>(T,F),9..15=>(F,F),16=>
> (T,F),
> 17..23=>(F,F),24=>(T,F),25..29=>(F,F),30..31=>(F,T),32=>(T,T),
> 33..49=>(F,T),50=>(T,T));
>
How about:
A : Theater := (
1 | 8 | 16 | 24 => (Reserved => True, Balcony => False),
2..7 | 9..15 | 17..23 | 25..29 => (Reserved => False, Balcony =>
False),
30..31 | 33..49 => (Reserved => False, Balcony => True),
32 | 50 => (Reserved => True, Balcony => True ));
> begin
>
> for Seat in Theater'range loop
> if Theater(Seat)(reserved) = F then
> Put(Seat, 1); New_Line;
> end if;
> end loop;
>
> end Ch4Ex22;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada code snippet help (array of arrays)
2009-05-14 8:05 ` Egil Høvik
@ 2009-05-14 15:16 ` Adam Beneschan
2009-05-14 17:14 ` Dmitry A. Kazakov
0 siblings, 1 reply; 7+ messages in thread
From: Adam Beneschan @ 2009-05-14 15:16 UTC (permalink / raw)
On May 14, 1:05 am, Egil Høvik <egilho...@hotmail.com> wrote:
> > T: constant Boolean := True;
> > F: constant Boolean := False;
>
> No need to define your own constants... True and False are
> already enumerated values (constants) of type Boolean.
I think he defined those just for readability. If you have a large
constant array, it might look better, look more like a chart, take up
less space on the screen, be easier to line up, etc., if you can do it
with shorter names such as single letters. I've seen this sort of
thing done before.
-- Adam
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ada code snippet help (array of arrays)
2009-05-14 15:16 ` Adam Beneschan
@ 2009-05-14 17:14 ` Dmitry A. Kazakov
0 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2009-05-14 17:14 UTC (permalink / raw)
On Thu, 14 May 2009 08:16:22 -0700 (PDT), Adam Beneschan wrote:
> On May 14, 1:05 am, Egil H�vik <egilho...@hotmail.com> wrote:
>
>>> T: constant Boolean := True;
>>> F: constant Boolean := False;
>>
>> No need to define your own constants... True and False are
>> already enumerated values (constants) of type Boolean.
>
> I think he defined those just for readability. If you have a large
> constant array, it might look better, look more like a chart, take up
> less space on the screen, be easier to line up, etc., if you can do it
> with shorter names such as single letters. I've seen this sort of
> thing done before.
Well, in this case I have a better proposal:
X : constant Boolean_Array (1..100) :=
( 1..10 | 13..15 | 45 | 77 => True, others => False);
In fact, need to specify enumeration literals no more than just once!
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-05-14 17:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-13 14:11 Ada code snippet help (array of arrays) Vamp4L
2009-05-13 14:25 ` Georg Bauhaus
2009-05-13 14:28 ` Vamp4L
2009-05-13 15:05 ` Jacob Sparre Andersen
2009-05-14 8:05 ` Egil Høvik
2009-05-14 15:16 ` Adam Beneschan
2009-05-14 17:14 ` Dmitry A. Kazakov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox