comp.lang.ada
 help / color / mirror / Atom feed
* Re: Can I overload ": ="?
@ 1992-10-13  4:08 Michael Feldman
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Feldman @ 1992-10-13  4:08 UTC (permalink / raw)


In article <1992Oct12.194719.27071@fcom.cc.utah.edu> val@news.ccutah.edu (Val K
artchner) writes:
>(I happen to have run into a situation where this would be useful.  I've
>found a way around it, but I'd like to know if I can do it this way?)
>
>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?
>
Nope, sorry. Ada does not allow - under any circumstances - you to change
the meaning of :=.

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman
co-chair, SIGAda Education Committee

Professor, Dept. of Electrical Engineering and Computer Science
School of Engineering and Applied Science
The George Washington University
Washington, DC 20052 USA
(202) 994-5253 (voice)
(202) 994-5296 (fax)
mfeldman@seas.gwu.edu (Internet)

"Americans wants the fruits of patience -- and they want them now."
------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I overload ":="?
@ 1992-10-13 12:07 cis.ohio-state.edu!news.sei.cmu.edu!firth
  0 siblings, 0 replies; 4+ messages in thread
From: cis.ohio-state.edu!news.sei.cmu.edu!firth @ 1992-10-13 12:07 UTC (permalink / raw)


In article <1992Oct12.194719.27071@fcom.cc.utah.edu> val@news.ccutah.edu (Val K
artchner) 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I overload ":="?
@ 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
  0 siblings, 0 replies; 4+ messages in thread
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 @ 1992-10-14 16:22 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Can I overload ":="?
@ 1992-10-14 20:27 Mark A Biggar
  0 siblings, 0 replies; 4+ messages in thread
From: Mark A Biggar @ 1992-10-14 20:27 UTC (permalink / raw)


In article <mmaccorm.35@fox.nstn.ns.ca> mmaccorm@fox.nstn.ns.ca (Mike Mac Corma
ck) writes:
>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?

This doesn't work because overload resolution only works for subprograms.
The above declaration completely hides the type name "real", it doesn't
overload it.  The above declaration may even be illegal because the function
name "real" arleady hides the type name by the time the complier gets to the 
function return type.  Besides the above functions is better called "real_part"
to distinguish it form the complementary function "imaginary_part", unless
you wanted the modulas in which case overloading "abs" makes more sense.

--
Mark Biggar
mab@wdl1.wdl.loral.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1992-10-14 20:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-10-14 16:22 Can I overload ":="? 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
  -- strict thread matches above, loose matches on Subject: below --
1992-10-14 20:27 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

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