From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4ce5890331a5b529 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!f20g2000vbc.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Discriminants of tagged types Date: Wed, 27 Oct 2010 15:42:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: <79d95094-50a0-4748-a347-c44c4cf5c81f@f20g2000vbc.googlegroups.com> References: <14314714-e92c-4036-9cbb-da8e72489261@h7g2000yqn.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1288219369 18761 127.0.0.1 (27 Oct 2010 22:42:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 27 Oct 2010 22:42:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f20g2000vbc.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14873 Date: 2010-10-27T15:42:49-07:00 List-Id: On Oct 27, 3:07=A0pm, Yannick Duch=EAne (Hibou57) wrote: > I see your good point. > > I have something similar for Windows API interfacing (ex. for event =A0 > handlers whose parameters may be made of two short integer, a reference, = a =A0 > long integer, and so, in the same parameter, depending on a message ID). = =A0 > This is a particular case, because I use Unchecked_Union, and =A0 > Unchecked_Union requires a default value for the discriminant. > > Otherwise, in your example, I would say what you named Value, is not a = =A0 > Value, and rather an Expression, unless you meant an abstract view of wha= t =A0 > a Value is. Well, this was just intended to be an example, and it's best not to get hung up on one example. The idea was something like: suppose you're writing an Ada interpreter for the Perl language, which does not have strong typing. A Perl program can have a variable named $x, and the program could, at one point, assign $x=3D3; to give it an integer value, and later $x=3D"This is a string"; to give it a string value, say. The Ada interpreter would likely have some lookup table in which it would look up the name "$x" and this would give it some information about the current state of $x, with one of those pieces of information being the current value of $x. The idea here is that for a Perl assignment statement, the interpreter could look up the record containing $x and then reassign the value in that record to a new value, which would involve changing the discriminant. (Of course, this is a huge oversimplification of the Perl language. But it's the sort of thing that could work in simpler interpreters---and, in fact, I have used Ada for tools with command-line interfaces that would be considered simple interpreters. Also, of course, there are many other possible uses for variant records that have nothing to do with interpreters.) > As there are Integer_Value, Float_Value, String_Value, I suppose each of = =A0 > these three is associated to specific operations. So why not three types = ? =A0 > Tagged types derived from a root abstract tagged type ? Because the Ada record that contains information about $x cannot have a component of type Root_Value_Type'Class. The component would have to be of an *access* type to Root_Value_Type'Class, and that's where you start having to worry about allocation and memory leakage and the like. It's certainly one way to solve the problem, but it's not without cost, and for a *simple* case (Perl would not be a simple case, so it's a bad example), a variant record could be better. Memory management is never as simple as it seems. -- Adam