[comp.lang.modula2] Op overloading/var. parms

mdlcpgs@lhn.dsir.govt.nz (05/06/91)

> I agree that overloaded operators can be nice.  However, they also can
> be easily abused.  A popular one is to use + for string concatenation
> "'cause it's just like you're adding the two strings together."  Well,
> you aren't adding them you are concatenating them.  If "ab" + "cd" is
> "abcd" then 123 + 456 must =be123456, right?  :-)

Dont get this. "123" + "456" would indeed equal "123456"
	        123 + 456 = 579
A compiler is in real trouble if cant distinquish types. The parsing of
this as I see it is:
	without op overloading
	   a := "123" + "456"  should result in error message.
	with op overloading and + redef imported from string module then
	compiler uses the + redefinition when it discovers a,"123" and "456"
	are strings.

> 
> And as for complex numbers, if you have a good compiler that allows any
> type to be returned as a function result then:
> 
> a := Complex.Add(b,c);
> 
> is much clearer than your example (though in this case still not as nice
> as a:=b+c).


Better but what is status of structured returns in the proposed standard while
we are about it?

	Phil

seurer+@rchland.ibm.com (Bill Seurer) (05/07/91)

Excerpts from netnews.comp.lang.modula2: 6-May-91 Re: Op
overloading/var. parms mdlcpgs@lhn.dsir.govt.nz (1100)

> > "abcd" then 123 + 456 must =be123456, right?  :-)

> Dont get this. "123" + "456" would indeed equal "123456"
> 	        123 + 456 = 579

"123" + "456" would indeed (if + were string concatentation) be "123456"
but my example was the INTEGER 123 plus the INTEGER 456...  The point
was that concatenation is not the same as addition.  It is just more
obvious that it is "wrong" is you look at it from the other side (i.e.,
addition is the same as concatenation)..

- Bill Seurer         Programming Support   IBM Rochester, MN
  Prodigy: CNSX71A    Internet: seurer@rchland.vnet.ibm.com