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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.ams3.giganews.com!border2.nntp.ams3.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: peter.h.m.brooks@gmail.com (Peter Brooks) Newsgroups: comp.lang.ada Subject: Re: Variant record limitation - what's a better solution? Date: Wed, 10 Jul 2013 01:11:33 +0000 (UTC) Organization: albasani.net Message-ID: References: <0606a658-9816-4611-84dd-4f999bf6018e@googlegroups.com> <57dd4a15-f395-4938-89f2-027edadce24b@googlegroups.com> X-Trace: news.albasani.net CbxbYja4RHbc61eDw3HIQK/wLcdEHFUrg84iMXq1YSmEz2FCFo4uZ0gBv+nFrgzvZ1b+L+DMKj3gnZjY4ibqOxemcnFy0FpGJIEaBQihZF9pHBNgM6QC4/fPwNtXC/Kp NNTP-Posting-Date: Wed, 10 Jul 2013 01:11:33 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="6dR9whQWSVkzL16mzJX+VEinZXxMqT7ZvuZEEovpwktqTGS6uWN4m33LNLrp8SF7expC3/fWFQV2G80PMxAHq6UeMF+pJOqOFjfSmpqf9OPPJV9joNKuB1s9444ZNgMF"; mail-complaints-to="abuse@albasani.net" User-Agent: tin/2.1.2-20121224 ("Langholm") (UNIX) (Darwin/12.4.0 (x86_64)) Cancel-Lock: sha1:NVTUJPD0XCxmRA3SXc63rGVhtP4= X-Original-Bytes: 3175 Xref: number.nntp.dca.giganews.com comp.lang.ada:182409 Date: 2013-07-10T01:11:33+00:00 List-Id: Adam Beneschan 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.