comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier write-only address <gautier_niouzes@hotmail.com>
Subject: Re: Question on variant/discriminated records
Date: Thu, 31 Dec 2020 08:06:50 -0800 (PST)	[thread overview]
Message-ID: <8c9e6c01-495d-4bce-a6d1-c440f559d8bbn@googlegroups.com> (raw)
In-Reply-To: <5fedd239$0$21616$426a74cc@news.free.fr>

> > Imagine you have a function Evaluate (r : rec1_Type) return Float. 
> > Except in trivial cases like 
> > if r.option1 = b then result := result + r.y; end if; 
> > the compiler cannot guess the value of the discriminant. 
> >
> Isn't the discriminant stored in the record ?

Yes. But if both "y"s were allowed, the compiler should for the non-trivial cases, generate a hidden "case" instruction to select the right "y" depending on the value of option1 (both "y"s are not necessarily at the same position in the record). Certainly the language designers have considered the additional complexity and performance cost of that point. Fortunately the nested choice as suggested by Dmitry solves the problem.

  reply	other threads:[~2020-12-31 16:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-31 10:38 Question on variant/discriminated records reinert
2020-12-31 10:52 ` J-P. Rosen
2020-12-31 12:24   ` reinert
2020-12-31 12:46     ` Gautier write-only address
2020-12-31 12:57       ` reinert
2020-12-31 13:29       ` DrPi
2020-12-31 16:06         ` Gautier write-only address [this message]
2020-12-31 15:03 ` Dmitry A. Kazakov
2021-01-01  9:19   ` reinert
replies disabled

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