From: dog.ee.lbl.gov!hellgate.utah.edu!caen!destroyer!cs.ubc.ca!utcsri!torn!csd .unb.ca!morgan.ucs.mun.ca!nstn.ns.ca!mmaccorm@ucbvax.Berkeley.EDU (Mike Mac Co
Subject: Re: Can I overload ":="?
Date: 14 Oct 92 16:22:58 GMT [thread overview]
Message-ID: <mmaccorm.35@fox.nstn.ns.ca> (raw)
In article <1992Oct13.120715.7253@sei.cmu.edu> firth@sei.cmu.edu (Robert Firth)
writes:
>In article <1992Oct12.194719.27071@fcom.cc.utah.edu> val@news.ccutah.edu (Val
Kartchner) writes:
>>I would like to define what happens when I assign a value of one type (say
>>complex) to a variable of another type (say real). Can I change what is
>>meant in Ada by the operation ":=" like I can do with the other operators,
>>or am I stuck with assignment of a type to a variable of that type?
>The direct answer is you can't do it: assignment works only between a
>value and a variable of the same type, and you can't redefine or
>overload the ":=" operation.
>The indirect answer is that you can define a type transfer function
>as anything you please, eg
> function Convert (x:Chipmunk) return Integer;
>and then say
> line_length := Convert(Dale);
>And, of course, you can overload Convert on any parameter and result type,
>so need choose only one name for all type conversion functions. Jean
>Ichbiah's suggestion (with which I do not agree!) is that you use the
>unary "+" operator for type conversion.
Couldn't you use the type name as type conversion operator? If you had a
type "Complex", and wanted to convert it to a real, couldn't you
overload "real" as follows:
function real(c :Complex) return real;
and then use the statement
r := real(c);
to convert it to a real?
Micronav International Inc
P.O.Box 1523 / 104 Marine Drive
Sydport Industrial Park,
Sydney, N.S. Canada B1P 6R7
Tel: 902-564-8833 Fax: 902-564-8764
next reply other threads:[~1992-10-14 16:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-10-14 16:22 dog.ee.lbl.gov!hellgate.utah.edu!caen!destroyer!cs.ubc.ca!utcsri!torn!csd.unb.ca!morgan.ucs.mun.ca!nstn.ns.ca!mmaccorm [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-10-14 20:27 Can I overload ":="? Mark A Biggar
1992-10-13 12:07 cis.ohio-state.edu!news.sei.cmu.edu!firth
1992-10-13 4:08 Can I overload ": ="? Michael Feldman
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox