From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=BAYES_40 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 14 Oct 92 16:22:58 GMT 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 rmack) Subject: Re: Can I overload ":="? Message-ID: List-Id: 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