comp.lang.ada
 help / color / mirror / Atom feed
* Re: Using an array of variant records
  2000-01-27  0:00 Using an array of variant records Scott Ingram
@ 2000-01-27  0:00 ` David
  2000-01-28  0:00   ` Scott Ingram
  0 siblings, 1 reply; 3+ messages in thread
From: David @ 2000-01-27  0:00 UTC (permalink / raw)
  To: scott

In article <389089CB.85F9FF72@silver.jhuapl.edu>,
  Scott Ingram <scott@silver.jhuapl.edu> wrote:
> What I would like to do is to treat a set of variant records
> as an array.  The discrimanant of the records is unconstrained,
> but I seem unable to access it when trying to initialize the
> record as element of an array.  The example below illustrates
> what I want to accomplish, but gnat complains that it expects
> a selector at the point that I want to select the discriminant.
>
> Is it possible to do what I want?
>
> procedure snake_test is
>    type snake is (garter, green);
>    type snake_health is
>       record
>          Shed : Boolean;
>          Active : Boolean;
>    end record;
>    type captive_snake (caged : Boolean := False) is
>       record
>         snake_kind : snake;
>       case caged is
>          when true =>
>             health : snake_health;
>          when others =>
>             null;
>       end case;
>    end record;
>    type snake_array is array (1..3) of captive_snake;
> S1 : snake_array;
> begin
>    for i in 1..3 loop
>       S1(i).(caged => True,
>             snake_kind => green,
>             health => (shed => true, active => true));
>    end loop;
> end snake_test;
>
> Output from gnat:
>
> Compiling: snake_test.adb (source file time stamp: 2000-01-27
18:07:28)
>     22.       S1(i).(caged => True,
>                     |
>         >>> selector expected
>
> Is there something that I have overlooked?
Yes.  The expression to the right of the dot is not a selector, but an
aggregate.

I believe you wanted :

       S1(i) := (caged      => True,
                 snake_kind => green,
                 health     => (shed => true,
                                active => true));


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Using an array of variant records
@ 2000-01-27  0:00 Scott Ingram
  2000-01-27  0:00 ` David
  0 siblings, 1 reply; 3+ messages in thread
From: Scott Ingram @ 2000-01-27  0:00 UTC (permalink / raw)


What I would like to do is to treat a set of variant records
as an array.  The discrimanant of the records is unconstrained,
but I seem unable to access it when trying to initialize the
record as element of an array.  The example below illustrates
what I want to accomplish, but gnat complains that it expects
a selector at the point that I want to select the discriminant.

Is it possible to do what I want?  

procedure snake_test is
   type snake is (garter, green);
   type snake_health is
      record
         Shed : Boolean;
         Active : Boolean;
   end record;
   type captive_snake (caged : Boolean := False) is
      record
        snake_kind : snake;
      case caged is
         when true =>
            health : snake_health;
         when others =>
            null;
      end case;
   end record;
   type snake_array is array (1..3) of captive_snake;
S1 : snake_array;
begin
   for i in 1..3 loop
      S1(i).(caged => True,
            snake_kind => green,
            health => (shed => true, active => true));
   end loop;
end snake_test;

Output from gnat:

Compiling: snake_test.adb (source file time stamp: 2000-01-27 18:07:28)
    22.       S1(i).(caged => True,
                    |
        >>> selector expected

Is there something that I have overlooked?  TIA,
-- 
Scott Ingram
Sonar Processing and Analysis Laboratory
Johns Hopkins University Applied Physics Laboratory




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

* Re: Using an array of variant records
  2000-01-27  0:00 ` David
@ 2000-01-28  0:00   ` Scott Ingram
  0 siblings, 0 replies; 3+ messages in thread
From: Scott Ingram @ 2000-01-28  0:00 UTC (permalink / raw)


David, C., Hoos, "Sr." wrote:

> > Is there something that I have overlooked?
> Yes.  The expression to the right of the dot is not a selector, but an
> aggregate.
> 
> I believe you wanted :
> 
>        S1(i) := (caged      => True,
>                  snake_kind => green,
>                  health     => (shed => true,
>                                 active => true));
Duh.  Thought that I had tried that, but since the actual aggregate is
far
more complex than the example above I missed something when trying to
assign it.  Gnat just happened to pick the assignment operator as the
spot
to point out that the expression on the rhs was wrong.  :)
-- 
Scott Ingram
Sonar Processing and Analysis Laboratory
Johns Hopkins University Applied Physics Laboratory




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

end of thread, other threads:[~2000-01-28  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-27  0:00 Using an array of variant records Scott Ingram
2000-01-27  0:00 ` David
2000-01-28  0:00   ` Scott Ingram

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