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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,89814ab9e757697a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-19 20:33:29 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: 18k11tm001@sneakemail.com (Russ) Newsgroups: comp.lang.ada Subject: Re: user-defined type conversion Date: 19 May 2002 20:33:29 -0700 Organization: http://groups.google.com/ Message-ID: References: NNTP-Posting-Host: 63.194.87.148 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1021865609 1615 127.0.0.1 (20 May 2002 03:33:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 20 May 2002 03:33:29 GMT Xref: archiver1.google.com comp.lang.ada:24400 Date: 2002-05-20T03:33:29+00:00 List-Id: sk wrote in message news:... > Hi, > 18k11tm001@sneakemail.com (Russ) : > >type inches is new float; > >type feet is new float; > > >function inches ( arg: feet ) return inches is > > begin > > return inches ( 12.0 * float(feet) ); > > end inches; > > ... > > > Type conversion IS a function! ... > > You are dealing with two different conversions, a type > conversion and a "units" conversion. > > The other problem is Float(Feet), do you mean Float(Arg) ? Yes. > function To_inches ( arg: feet ) return inches is > begin > return > Inches ( -- Type conversion > 12.0 * Arg -- Unit conversion > ); > end To_inches; The reason I meant to use "12.0 * float(arg)" rather than simply "12.0 * arg" is so that I avoid an infinite recursion (using the function name "inches", the same as the type name). It should work fine that way, except that Ada doesn't allow the same name to be used for a type and a function. I contend that there is no inherent reason that it shouldn't. I don't see how it is possible for the compiler to confuse a type with a function. If Ada allowed that, I could write my own type/unit conversions that have the same syntax as built-in type conversions.