From: dean@rsch.WISC.EDU (Dean Luick)
Subject: variant records
Date: Fri, 31-Oct-86 04:08:54 EST [thread overview]
Date: Fri Oct 31 04:08:54 1986
Message-ID: <2886@rsch.WISC.EDU> (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
next reply other threads:[~1986-10-31 9:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
1986-10-31 9:08 Dean Luick [this message]
1986-11-03 14:17 ` variant records Bev Sobelman
1986-11-05 16:35 ` stuart
1986-11-06 15:40 ` stt
-- strict thread matches above, loose matches on Subject: below --
1999-09-14 0:00 Variant Records Shawn Barber
1999-09-14 0:00 ` Matthew Heaney
1999-09-14 0:00 ` David C. Hoos, Sr.
1999-09-14 0:00 ` Mark Lundquist
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox