From: GOTO Kentaro Date: 2002-09-11T02:40:22+09:00 Subject: Re: Larry Wall's comments on Ruby At Wed, 11 Sep 2002 01:14:23 +0900, Giuseppe Bilotta wrote: > > I find that highly unnatural because we've been learning since grade school > > that a + b = b + a. > > > > If the objects don't satisfy that property they should be using a different > > symbol. > > No way. For example, product is commutative only up to complex > numbers. If you move on to quaternions, you get a noncommutative > product. And as for noncommutative sum ... think for example about > strings. "a" + "b" != "b" + "a" Well, we often choose `+' for commutative operation in algebra indeed. Several years ago, I proposed to define String#* as concatination because `*' can read as product and String is sometimes regarded as semigroup which has product defined as concatination in theoretical computer science. String#* could give some merit: - Product may be noncommutative and a*b != b*a doesn't surprise us not so much. - Repeatation would be naturally replaced with String#** and it looks clearly noncommutative. - A user could define 1+"2" and "2"+1 as 3 like Perl. I proposed also Array#*. But those proposals were rejected because `*' looked strange for many people (including matz). However I think that decision was not bad because I can use for Enumerable#* for direct product now. For example: require 'product' for i,j,k in (1..2)*(3..4)*(2..3) puts "#{i}+#{j}+#{k} = #{i+j+k}" end generates: 1+3+2 = 6 1+3+3 = 7 1+4+2 = 7 1+4+3 = 8 2+3+2 = 7 2+3+3 = 8 2+4+2 = 8 2+4+3 = 9 http://www.ruby-lang.org/en/raa-list.rhtml?name=product -- Gotoken