comp.lang.ada
 help / color / mirror / Atom feed
From: 18k11tm001@sneakemail.com (Russ)
Subject: Re: user-defined type conversion
Date: 19 May 2002 20:33:29 -0700
Date: 2002-05-20T03:33:29+00:00	[thread overview]
Message-ID: <bebbba07.0205191933.79195253@posting.google.com> (raw)
In-Reply-To: mailman.1021834982.12823.comp.lang.ada@ada.eu.org

sk <noname@myob.com> wrote in message news:<mailman.1021834982.12823.comp.lang.ada@ada.eu.org>...
> 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.



  reply	other threads:[~2002-05-20  3:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-19  7:44 user-defined type conversion Russ
2002-05-19  8:54 ` martin.m.dowie
2002-05-19 10:44 ` David C. Hoos, Sr.
2002-05-19 18:29   ` Russ
2002-05-19 20:58     ` David C. Hoos, Sr.
2002-05-19 21:12     ` Jeffrey Carter
2002-05-21  9:18       ` Dmitry A. Kazakov
2002-05-19 19:01 ` sk
2002-05-20  3:33   ` Russ [this message]
2002-05-20 19:27     ` Randy Brukardt
2002-05-20 19:45       ` David C. Hoos
2002-05-19 21:17 ` Jeffrey Carter
2002-05-20  3:25   ` Russ
2002-05-20  6:21     ` Jeffrey Carter
2002-05-21  9:30       ` Dmitry A. Kazakov
     [not found]     ` <mailman.1021892102.6644.comp.lang.ada@ada.eu.org>
2002-05-20 19:26       ` Russ
2002-05-21  9:35         ` Dmitry A. Kazakov
2002-05-22  4:32         ` Russ
replies disabled

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