comp.lang.ada
 help / color / mirror / Atom feed
From: peter.h.m.brooks@gmail.com (Peter Brooks)
Subject: Re: Variant record limitation - what's a better solution?
Date: Wed, 10 Jul 2013 01:11:33 +0000 (UTC)
Date: 2013-07-10T01:11:33+00:00	[thread overview]
Message-ID: <kricc4$7tn$1@news.albasani.net> (raw)
In-Reply-To: e6bc0a74-c905-4d89-ae0c-d3d5172ab318@googlegroups.com

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.


  reply	other threads:[~2013-07-10  1:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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