comp.lang.ada
 help / color / mirror / Atom feed
* Variant record limitation - what's a better solution?
@ 2013-07-03  7:52 Peter Brooks
  2013-07-03  8:11 ` Georg Bauhaus
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Peter Brooks @ 2013-07-03  7:52 UTC (permalink / raw)


I see that I can't do what I'd like to with a variant record. What should I be doing?

Here's an example:

type
my_object(X : size_type) is
       record
              name : string(1..80);
              case X is
                 when small => Y : small_type; -- line 20
                 when medium => Y : medium_type; -- line 21
                 when large => Y: large_type; -- line 22
              end case;
       end record;

The errors are:
line 21  'Y' conflicts with declaration at line 20
line 22 'Y' conflicts with declaration at line 21

I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?

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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
@ 2013-07-03  8:11 ` Georg Bauhaus
  2013-07-03  9:39   ` Peter Brooks
  2013-07-03 16:23 ` Jeffrey Carter
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 14+ messages in thread
From: Georg Bauhaus @ 2013-07-03  8:11 UTC (permalink / raw)


On 03.07.13 09:52, Peter Brooks wrote:
> I see that I can't do what I'd like to with a variant record. What should I be doing?
>
> Here's an example:
>
> type
> my_object(X : size_type) is
>         record
>                name : string(1..80);
>                case X is
>                   when small => Y : small_type; -- line 20
>                   when medium => Y : medium_type; -- line 21
>                   when large => Y: large_type; -- line 22
>                end case;
>         end record;
>
> The errors are:
> line 21  'Y' conflicts with declaration at line 20
> line 22 'Y' conflicts with declaration at line 21
>
> I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?
>

Different types are o.K., the same name for different
components isn't. Three overloaded accessor functions Y
each returning one of the components will work.

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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  8:11 ` Georg Bauhaus
@ 2013-07-03  9:39   ` Peter Brooks
  0 siblings, 0 replies; 14+ messages in thread
From: Peter Brooks @ 2013-07-03  9:39 UTC (permalink / raw)


Thank you!

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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
  2013-07-03  8:11 ` Georg Bauhaus
@ 2013-07-03 16:23 ` Jeffrey Carter
  2013-07-03 18:35 ` Shark8
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Jeffrey Carter @ 2013-07-03 16:23 UTC (permalink / raw)


On 07/03/2013 12:52 AM, Peter Brooks wrote:
>
> type
> my_object(X : size_type) is
>         record
>                name : string(1..80);
>                case X is
>                   when small => Y : small_type; -- line 20
>                   when medium => Y : medium_type; -- line 21
>                   when large => Y: large_type; -- line 22
>                end case;
>         end record;
>
> The errors are:
> line 21  'Y' conflicts with declaration at line 20
> line 22 'Y' conflicts with declaration at line 21
>
> I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?

The problem isn't the types but the component identifiers. Each component name 
must be unique, even across different variants. So you could do something like

type My_Object (Size : Size_ID) is record
    Name : String (1 .. 80);

    case Size is
    when Small =>
       Y_Small : Small_Value;
    when Medium =>
       Y_Medium : Medium_Value;
    when Large =>
       Y_Large : Large_Value;
    end case;
end record;

-- 
Jeff Carter
"My brain hurts!"
Monty Python's Flying Circus
21


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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
  2013-07-03  8:11 ` Georg Bauhaus
  2013-07-03 16:23 ` Jeffrey Carter
@ 2013-07-03 18:35 ` Shark8
  2013-07-03 19:26 ` Adam Beneschan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: Shark8 @ 2013-07-03 18:35 UTC (permalink / raw)


On Wednesday, July 3, 2013 1:52:12 AM UTC-6, Peter Brooks wrote:
> 
> Here's an example:
> 
> type
> 
> my_object(X : size_type) is
>        record
>               name : string(1..80);
>               case X is
>                  when small  => Y : small_type; -- line 20
>                  when medium => Y : medium_type; -- line 21
>                  when large  => Y : large_type; -- line 22
>               end case;
> 
>        end record;
> 
> 
> I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?

Well, you can use subtypes as you might originally think (but there's a bit of a hiccup) -- example:
    type small_type  is range 0..2**8-1;
    type medium_type is range 0..2**16-1;
    type large_type  is range 0..2**32-1;
    
    
    type size_type is ( small, medium, large );
    
    type my_object(Size : size_type) is
	record
	    name : string(1..80);
	    case Size is
		when small  => small_data : small_type;
		when medium => med_data   : medium_type;
		when large  => large_data : large_type;
	    end case;
	end record;

    subtype small_object  is my_object( Size => small );
    subtype medium_object is my_object( Size => medium );
    subtype large_object  is my_object( Size => large );
    
    
    -- Using Ada 2012 expression-functions for brevity.
    function Get_Data( Item : in small_object ) return small_type is
	( Item.small_data );
    function Get_Data( Item : in medium_object ) return medium_type is
	( Item.med_data );
    function Get_Data( Item : in large_object ) return large_type is
	( Item.large_data );
    
    J : my_object:= ( Size => small,
		      small_data => 128,
		      Name => ('B','o','b', others => ASCII.NUL) 
		    );
    K :  constant integer := Integer(  Get_Data( J )  );

Now the assignment to K shows the problem with this approach, as the compiler points out: ambiguous operand in conversion.

This is because even though the compiler knows the types involved a differing subtypes it cannot [generally] distinguish between them like it would with a case-statement's case coverage. (That is, subtypes in-general aren't mutually exclusive.)

At this point there are two obvious ways to go about addressing this:
1)  add a qualification: e.g. Integer(  Small'(Get_Data( J ))  ); 
    -- The above will make the assignment to K work.
2)  go to a tagged record-type and use standard OO-methodologies there.




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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
                   ` (2 preceding siblings ...)
  2013-07-03 18:35 ` Shark8
@ 2013-07-03 19:26 ` Adam Beneschan
  2013-07-09 11:48   ` Peter Brooks
  2013-07-03 20:55 ` Per Sandberg
  2013-07-09  6:38 ` Peter Brooks
  5 siblings, 1 reply; 14+ messages in thread
From: Adam Beneschan @ 2013-07-03 19:26 UTC (permalink / raw)


On Wednesday, July 3, 2013 12:52:12 AM UTC-7, Peter Brooks wrote:
> I see that I can't do what I'd like to with a variant record. What should I be doing?
> 
> Here's an example:
> 
> type
> my_object(X : size_type) is
>        record
>               name : string(1..80);
>               case X is
>                  when small => Y : small_type; -- line 20
>                  when medium => Y : medium_type; -- line 21
>                  when large => Y: large_type; -- line 22
>               end case;
>        end record;
> 
> The errors are:
> line 21  'Y' conflicts with declaration at line 20
> line 22 'Y' conflicts with declaration at line 21
> 
> I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?

Peter,

I think others have given adequate answers for how to change the example to make it compile.  One other thing you might want to consider is using tagged types instead of variant records.  Variant records have been in Ada since Ada 83, but I think adding tagged types to Ada 95 has lessened (but not eliminated) the need to use variant records in many cases.  The basic idea would look something like this:

   type My_Object is abstract tagged
      record
         name : string (1..80);
      end record;

   type My_Object_Small is new My_Object with record
      Y : Small_Type;
   end record;
   type My_Object_Medium is new My_Object with record
      Y : Medium_Type;
   end record;
   type My_Object_Large is new My_Object with record
      Y : Large_Type;
   end record;

The advantage is that for whatever operations you want to define for My_Object, you don't have to write them all as operations that do a CASE on a discriminant.  Say you need an operation that dumps all the data in the object; instead of writing a big Dump procedure that handles all the possible cases, you can define 

   procedure Dump (Obj : My_Object) is abstract;

and override it for each of the derived types:

   overriding
   procedure Dump (Obj : My_Object_Small);  -- similarly for the other two

where the body of each one is tailored to the data in that particular object.  

It's just something to consider.  A variant record may be more appropriate in some cases; and I think in some simpler cases, the tagged type solution may be too heavy to be worth the effort.  But it's a possibility that I think should be considered, depending on your actual application.

                          -- Adam

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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
                   ` (3 preceding siblings ...)
  2013-07-03 19:26 ` Adam Beneschan
@ 2013-07-03 20:55 ` Per Sandberg
  2013-07-09  6:38 ` Peter Brooks
  5 siblings, 0 replies; 14+ messages in thread
From: Per Sandberg @ 2013-07-03 20:55 UTC (permalink / raw)


Just curious.

This is how you want to do something, and if you want a deeper answer
why not try to state what you want to do on a higher level since Ada is
a high level language.

/Persan



On Wed, 3 Jul 2013 00:52:12 -0700 (PDT)
Peter Brooks <peter.h.m.brooks@gmail.com> wrote:

> I see that I can't do what I'd like to with a variant record. What
> should I be doing?
> 
> Here's an example:
> 
> type
> my_object(X : size_type) is
>        record
>               name : string(1..80);
>               case X is
>                  when small => Y : small_type; -- line 20
>                  when medium => Y : medium_type; -- line 21
>                  when large => Y: large_type; -- line 22
>               end case;
>        end record;
> 
> The errors are:
> line 21  'Y' conflicts with declaration at line 20
> line 22 'Y' conflicts with declaration at line 21
> 
> I was hoping to have a different type depending on the case, but this
> doesn't seem allowed. What would achieve this?


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

* Re: Variant record limitation - what's a better solution?
  2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
                   ` (4 preceding siblings ...)
  2013-07-03 20:55 ` Per Sandberg
@ 2013-07-09  6:38 ` Peter Brooks
  2013-07-09  7:49   ` Simon Wright
                     ` (2 more replies)
  5 siblings, 3 replies; 14+ messages in thread
From: Peter Brooks @ 2013-07-09  6:38 UTC (permalink / raw)


Peter Brooks <peter.h.m.brooks@gmail.com> wrote:

I'm still having trouble with this. I've tried using functions, as suggested, but it doesn't allow overloaded functions in the varient part. Here's what I tried:


"
type
small_lorry_load is new integer range 1..2;
type
medium_lorry_load is new integer range 1..18;
type
large_lorry_load is new integer range 1..36;
type
all_lorry_loads is new integer range 1..36;

type
lorry_size is (small,medium,large);

type
lorry_number_plate is new string(1..8);

function load(x : lorry_size := small) return small_lorry_load;
function load(x : lorry_size := medium) return  medium_lorry_load;
function load(x : lorry_size := large) return large_lorry_load;


type
lorry_type(lorry : lorry_size) is
        record
                number_plate : lorry_number_plate;
                location : depot_name_type;
                destination : depot_name_type;
                case lorry is
                        when small => lorry_load : load(lorry);
                        when medium => lorry_load : load(lorry);
                        when large => lorry_load : load(lorry);
                end case;
        end record;
"

I know that the syntax is wrong - I've been trying all sorts of alternatives. What have I not understood?


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

* Re: Variant record limitation - what's a better solution?
  2013-07-09  6:38 ` Peter Brooks
@ 2013-07-09  7:49   ` Simon Wright
  2013-07-09  8:22   ` Georg Bauhaus
  2013-07-09 14:12   ` Eryndlia Mavourneen
  2 siblings, 0 replies; 14+ messages in thread
From: Simon Wright @ 2013-07-09  7:49 UTC (permalink / raw)


peter.h.m.brooks@gmail.com (Peter Brooks) writes:

> I'm still having trouble with this. I've tried using functions, as
> suggested, but it doesn't allow overloaded functions in the varient
> part. Here's what I tried:

I think that people meant you should hide the awkwardness of the
*unavoidably* different names by using functions to encapsulate the
differences.

Something like this (using Ada2012 expression functions, hope that
doesn't confuse):

   package Lorries is

      type Lorry_Load is new Integer range 1 .. 36;

      type Lorry_Size is (Small, Medium, Large);

      type Lorry_Type (Lorry : Lorry_Size) is private;

      type Lorry_Number_Plate is new String (1 .. 8);

      function Plate (L : Lorry_Type) return Lorry_Number_Plate;

      function Load (L : Lorry_Type) return Lorry_Load;

   private

      subtype Small_Lorry_Load is Lorry_Load range 1 .. 2;
      subtype Medium_Lorry_Load is Lorry_Load range 1 .. 18;
      subtype Large_Lorry_Load is Lorry_Load range 1 .. 36;

      type Lorry_Type (Lorry : Lorry_Size) is
         record
            Number_Plate : Lorry_Number_Plate;
            --  Location : Depot_Name_Type;
            --  Destination : Depot_Name_Type;
            case Lorry is
               when Small  => Small_Load : Small_Lorry_Load;
               when Medium => Medium_Load : Medium_Lorry_Load;
               when Large  => Large_Load : Large_Lorry_Load;
            end case;
         end record;

      function Plate (L : Lorry_Type) return Lorry_Number_Plate is
         (L.Number_Plate);

      function Load (L : Lorry_Type) return Lorry_Load is
         (case L.Lorry is
            when Small => L.Small_Load,
            when Medium => L.Medium_Load,
            when Large => L.Large_Load);

   end Lorries;


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

* Re: Variant record limitation - what's a better solution?
  2013-07-09  6:38 ` Peter Brooks
  2013-07-09  7:49   ` Simon Wright
@ 2013-07-09  8:22   ` Georg Bauhaus
  2013-07-09 14:12   ` Eryndlia Mavourneen
  2 siblings, 0 replies; 14+ messages in thread
From: Georg Bauhaus @ 2013-07-09  8:22 UTC (permalink / raw)


On 09.07.13 08:38, Peter Brooks wrote:

> function load(x : lorry_size := small) return small_lorry_load;
> function load(x : lorry_size := medium) return  medium_lorry_load;
> function load(x : lorry_size := large) return large_lorry_load;
>
>
> type
> lorry_type(lorry : lorry_size) is
>          record
>                  number_plate : lorry_number_plate;
>                  location : depot_name_type;
>                  destination : depot_name_type;
>                  case lorry is
>                          when small => lorry_load : load(lorry);
>                          when medium => lorry_load : load(lorry);
>                          when large => lorry_load : load(lorry);
>                  end case;
>          end record;
> "
>
> I know that the syntax is wrong - I've been trying all sorts of alternatives. What have I not understood?

Adam's and Simon's solutions should work better, I think. This one
will make a discriminant check fail if a caller mistakenly loads
a large size from a small lorry, say.

   type
      lorry_type(lorry : lorry_size) is private;

    function load(L : Lorry_type) return small_lorry_load;
    function load(L : Lorry_type) return  medium_lorry_load;
    function load(L : Lorry_type) return large_lorry_load;

private

    type
      lorry_type(lorry : lorry_size) is
         record
                 number_plate : lorry_number_plate;
                 location : depot_name_type;
                 destination : depot_name_type;
                 case lorry is
                         when small => small_load : small_lorry_load;
                         when medium => medium_load : medium_lorry_load;
                         when large => large_load : large_lorry_Load;
                 end case;
         end record;

The bodies of the load functions will be

    function load(L : Lorry_type) return  Medium_Lorry_Load is
    begin
       return L.Medium_Load;
    end Load;

and similarly for the other two functions. (They are operation of
type lorry_type, hence the parameter L). A caller will then
declare
   x : large_lorry_load;
begin
   x := load(my_lorry);
end
after which X will have a copy of the large component of L, provided
the discriminant matches, i.e. my_lorry.lorry = large.
If not, the program raises constraint_error.



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

* Re: Variant record limitation - what's a better solution?
  2013-07-03 19:26 ` Adam Beneschan
@ 2013-07-09 11:48   ` Peter Brooks
  2013-07-09 15:11     ` Adam Beneschan
  0 siblings, 1 reply; 14+ messages in thread
From: Peter Brooks @ 2013-07-09 11:48 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> wrote:
> On Wednesday, July 3, 2013 12:52:12 AM UTC-7, Peter Brooks wrote:
>> I see that I can't do what I'd like to with a variant record. What should I be doing?
>> 
>> Here's an example:
>> 
>> type
>> my_object(X : size_type) is
>>        record
>>               name : string(1..80);
>>               case X is
>>                  when small => Y : small_type; -- line 20
>>                  when medium => Y : medium_type; -- line 21
>>                  when large => Y: large_type; -- line 22
>>               end case;
>>        end record;
>> 
>> The errors are:
>> line 21  'Y' conflicts with declaration at line 20
>> line 22 'Y' conflicts with declaration at line 21
>> 
>> I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this?
> 
> Peter,
> 
> I think others have given adequate answers for how to change the example to make it compile.  One other thing you might want to consider is using tagged types instead of variant records.  Variant records have been in Ada since Ada 83, but I think adding tagged types to Ada 95 has lessened (but not eliminated) the need to use variant records in many cases.  The basic idea would look something like this:
> 
>   type My_Object is abstract tagged
>      record
>         name : string (1..80);
>      end record;
> 
>   type My_Object_Small is new My_Object with record
>      Y : Small_Type;
>   end record;
>   type My_Object_Medium is new My_Object with record
>      Y : Medium_Type;
>   end record;
>   type My_Object_Large is new My_Object with record
>      Y : Large_Type;
>   end record;
> 
> The advantage is that for whatever operations you want to define for My_Object, you don't have to write them all as operations that do a CASE on a discriminant.  Say you need an operation that dumps all the data in the object; instead of writing a big Dump procedure that handles all the possible cases, you can define 
> 
>   procedure Dump (Obj : My_Object) is abstract;
> 
> and override it for each of the derived types:
> 
>   overriding
>   procedure Dump (Obj : My_Object_Small);  -- similarly for the other two
> 
> where the body of each one is tailored to the data in that particular object.  
> 
> It's just something to consider.  A variant record may be more appropriate in some cases; and I think in some simpler cases, the tagged type solution may be too heavy to be worth the effort.  But it's a possibility that I think should be considered, depending on your actual application.
> 
Thank you for that idea. I think that that problably would make more sense for what I'm wanting to do..

I'm still not quite sure why a variant record can't have overloaded functions or entities, but I'm happy that it can't. Overriding the specific actions will work for me though.

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

* Re: Variant record limitation - what's a better solution?
  2013-07-09  6:38 ` Peter Brooks
  2013-07-09  7:49   ` Simon Wright
  2013-07-09  8:22   ` Georg Bauhaus
@ 2013-07-09 14:12   ` Eryndlia Mavourneen
  2 siblings, 0 replies; 14+ messages in thread
From: Eryndlia Mavourneen @ 2013-07-09 14:12 UTC (permalink / raw)


On Tuesday, July 9, 2013 1:38:09 AM UTC-5, Peter Brooks wrote:
> Peter Brooks <peter.h.m.brooks@gmail.com> wrote:
> 
> I'm still having trouble with this. I've tried using functions, as suggested, but it doesn't allow overloaded functions in the varient part. Here's what I tried:
> 
> "
> type
> small_lorry_load is new integer range 1..2;
> type
> medium_lorry_load is new integer range 1..18;
> type
> large_lorry_load is new integer range 1..36;
> type
> all_lorry_loads is new integer range 1..36;
> 
> type
> lorry_size is (small,medium,large);
> 
> type
> lorry_type(lorry : lorry_size) is
>         record
>                 number_plate : lorry_number_plate;
>                 location : depot_name_type;
>                 destination : depot_name_type;
>                 case lorry is
>                         when small => lorry_load : load(lorry);
>                         when medium => lorry_load : load(lorry);
>                         when large => lorry_load : load(lorry)
>                 end case;
>         end record; 
> "
> 
> I know that the syntax is wrong - I've been trying all sorts of alternatives. What have I not understood?

As a point of instruction, the Lorry_Load types also could be defined like this:

   type    All_Lorry_Loads   is range 1..36;
   subtype Small_Lorry_Load  is All_Lorry_Loads range 1..2;
   subtype Medium_Lorry_Load is All_Lorry_Loads range 1..18;
   subtype Large_Lorry_Load  is All_Lorry_Loads range 1..36;

which will make all the Lorry_Load types directly interrelated, thereby making the job of the programmer easier.  The definition of All_Lorry_Loads also allows the compiler to choose the exact representation of the integers.

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

* Re: Variant record limitation - what's a better solution?
  2013-07-09 11:48   ` Peter Brooks
@ 2013-07-09 15:11     ` Adam Beneschan
  2013-07-10  1:11       ` Peter Brooks
  0 siblings, 1 reply; 14+ messages in thread
From: Adam Beneschan @ 2013-07-09 15:11 UTC (permalink / raw)


On Tuesday, July 9, 2013 4:48:11 AM UTC-7, Peter Brooks wrote:

> I'm still not quite sure why a variant record can't have overloaded functions or entities, but I'm happy that it can't. Overriding the specific actions will work for me though.

If the kind of overloading you're thinking of is one where a function looks at the discriminant at runtime, and then decides which function to call based on the discriminant--it's not in the language because nobody put it in.  (What you're thinking of is closest to dispatching, or polymorphism, which Ada accomplishes with tagged types and other languages with inherited classes or whatever.)  

In Ada (and other languages I know that have overloading), overloading is only supported where the compiler can determine, *at* *compile* *time*, which function or procedure will be called.  It does this based on the types of the parameters and (in Ada) on the return type.  One thing to keep in mind is that when you declare a variant record, the variant record is only one *type*, not several types.  Thus you can't have overloading that distinguishes between whether you have a Lorry_Type with a Small load, or a Lorry_Type with a Medium load, etc.  It's all just one type, a Lorry_Type.

I hope this helps clear up some of the confusion.

                           -- Adam

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

* Re: Variant record limitation - what's a better solution?
  2013-07-09 15:11     ` Adam Beneschan
@ 2013-07-10  1:11       ` Peter Brooks
  0 siblings, 0 replies; 14+ messages in thread
From: Peter Brooks @ 2013-07-10  1:11 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> wrote:
> On Tuesday, July 9, 2013 4:48:11 AM UTC-7, Peter Brooks wrote:
> 
>> I'm still not quite sure why a variant record can't have overloaded functions or entities, but I'm happy that it can't. Overriding the specific actions will work for me though.
> 
> If the kind of overloading you're thinking of is one where a function looks at the discriminant at runtime, and then decides which function to call based on the discriminant--it's not in the language because nobody put it in.  (What you're thinking of is closest to dispatching, or polymorphism, which Ada accomplishes with tagged types and other languages with inherited classes or whatever.)  
> 
> In Ada (and other languages I know that have overloading), overloading is only supported where the compiler can determine, *at* *compile* *time*, which function or procedure will be called.  It does this based on the types of the parameters and (in Ada) on the return type.  One thing to keep in mind is that when you declare a variant record, the variant record is only one *type*, not several types.  Thus you can't have overloading that distinguishes between whether you have a Lorry_Type with a Small load, or a Lorry_Type with a Medium load, etc.  It's all just one type, a Lorry_Type.
> 
> I hope this helps clear up some of the confusion.
> 
Yes, it does, thank you very much! In object pascal, a variant record is created at the largest size of the possible  variants and you can use it to to type conversions, at run time. This is probably not good practice. It was something like this I was looking for - tagged records look the right port of call if I actually want to do something similar, as you say. However, I think it'll be better to do what's been suggested here. After all, I will know which sort of record I want at run time, so I don't really need a dynamic record.


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

end of thread, other threads:[~2013-07-10  1:11 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-03  7:52 Variant record limitation - what's a better solution? Peter Brooks
2013-07-03  8:11 ` Georg Bauhaus
2013-07-03  9:39   ` Peter Brooks
2013-07-03 16:23 ` Jeffrey Carter
2013-07-03 18:35 ` Shark8
2013-07-03 19:26 ` Adam Beneschan
2013-07-09 11:48   ` Peter Brooks
2013-07-09 15:11     ` Adam Beneschan
2013-07-10  1:11       ` Peter Brooks
2013-07-03 20:55 ` Per Sandberg
2013-07-09  6:38 ` Peter Brooks
2013-07-09  7:49   ` Simon Wright
2013-07-09  8:22   ` Georg Bauhaus
2013-07-09 14:12   ` Eryndlia Mavourneen

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