comp.lang.ada
 help / color / mirror / Atom feed
* Variant Records
@ 1999-09-14  0:00 Shawn Barber
  1999-09-14  0:00 ` Mark Lundquist
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Shawn Barber @ 1999-09-14  0:00 UTC (permalink / raw)


I have recently run into a small problem using variant 
records. I have been forced (against my better judgement) to 
use a data structure consisting of a variant record, and in 
this variant record a field of a particular variant is 
another variant record. I already know the pain which has 
been inflicted by using such a data structure. My question 
is when I do a compare, say Var_1 = Var_2 or an assignment 
are the fields compaired/assigned field by field or all at 
once or in some other manor? Thanks.

Shawn

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!





^ permalink raw reply	[flat|nested] 20+ messages in thread
* Variant records..
@ 2004-02-15 22:51 Ganesh Ramasivan
  2004-02-16 10:57 ` Preben Randhol
  2004-02-16 23:17 ` tmoran
  0 siblings, 2 replies; 20+ messages in thread
From: Ganesh Ramasivan @ 2004-02-15 22:51 UTC (permalink / raw)


In the following example, how would i forbid the user of data type Foo
from specifying the following:

John : Foo(Vehicle => MAN, Power => AUTOMATIC);

ie. is there a way to restrict the user from specifying certain types
as variants?

Thanks for your input.

Ganesh

Example:

procedure Variant is

   type Vehicle_Type is (CAR, LEGS, BIKE, PLANE);
   type Vehicle_Power is (MANUAL, AUTOMATIC);

   type Foo(Vehicle : Vehicle_Type; Power: Vehicle_Power) is
    record
        case Vehicle is
	     when CAR  =>
            null;
	     when LEGS =>
            null;
	     when BIKE =>
            null;
	     when PLANE =>
            null;
         when others =>
            null;
        end case;
    end record;

    Audi : Foo(Vehicle => CAR, Power => MANUAL); 
begin
 null;
end Variant;



^ permalink raw reply	[flat|nested] 20+ messages in thread
* variant records
@ 1986-10-31  9:08 Dean Luick
  1986-11-03 14:17 ` Bev Sobelman
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Dean Luick @ 1986-10-31  9:08 UTC (permalink / raw)


I am trying to write a stack package using a variant record in the main
record type and I am having great difficulty.  My problem is the following,
if I have the following definition:

type enum is (A, B, C, D);
type rec(kind : enum := A) is
    record
        case kind is
            when A | B =>       -- the actual values don't matter
                null;
            when C | D =>
                foo : integer;
    end record;

type node(xkind : enum := A);
type node_ptr is access node;
type node(xkind : enum := A) is
    record
        next : node_ptr;
        xrec : rec(xkind);
    end record;

stack       : node_ptr := NULL;
extra_nodes : node_ptr := NULL;

-- and I have the following later definiions:

procedure push(r : rec) is
    temp : node_ptr;
begin
    temp := new_node;
    temp.xrec := r;             -- position 'Z'
    temp.next := stack;
    stack := temp;
end push;

function new_node return node_ptr is
    temp : node_ptr;
begin
    temp := extra_nodes;
    if temp = NULL then
        temp := new node;
    else
        extra_nodes := extra_nodes.next;
    end if;
    return temp;
end new_node;

Suppose I create a rec of say, B, and try to push it.  At postion 'Z'
a constraint error is raised because of the different variant types ( in
the first case, temp's discriminant is A ).  Is there any way around this?
I was led to believe that I cound change the variant part of a type by
assigning it a whole aggregate (is that the right word?) say, like

case r.kind is 
    . . .
    when B =>
        temp.xrec := rec'(kind => B)
    . . .

Well, I tried that at position 'Z' and it failed.  I have run out of ideas.
Any help would be greatly appreciated.

dean

-- 

Dean Luick
uucp:	...!{allegra,harvard,ihnp4,seismo,topaz}!uwvax!dream!dean
arpa:	dean@dream.wisc.edu

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

end of thread, other threads:[~2004-02-17 15:43 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-14  0:00 Variant Records Shawn Barber
1999-09-14  0:00 ` Mark Lundquist
1999-09-14  0:00 ` David C. Hoos, Sr.
1999-09-14  0:00 ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
2004-02-15 22:51 Variant records Ganesh Ramasivan
2004-02-16 10:57 ` Preben Randhol
2004-02-16 15:25   ` Ganesh Ramasivan
2004-02-16 15:46     ` Ludovic Brenta
2004-02-16 16:16     ` Preben Randhol
2004-02-17 14:37       ` Ganesh Ramasivan
2004-02-17 15:43         ` Preben Randhol
2004-02-16 16:59   ` Ganesh Ramasivan
2004-02-16 20:14     ` Simon Wright
2004-02-17 14:56       ` Ganesh Ramasivan
2004-02-17 15:31         ` Robert I. Eachus
2004-02-16 23:17 ` tmoran
1986-10-31  9:08 variant records Dean Luick
1986-11-03 14:17 ` Bev Sobelman
1986-11-05 16:35 ` stuart
1986-11-06 15:40 ` stt

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