From: Martin DeMello Date: 2003-09-17T21:54:53+09:00 Subject: Re: Changing ==,>,<, etc Marcin 'Qrczak' Kowalczyk wrote: > Dnia czw 31. lipca 2003 22:03, Martin DeMello napisa?: > >> any? and all? are very receiver-centric - compare >> >> a.any? {|i| b.all? {|j| i < j} } >> >> with >> >> any(a) < all(b) >> >> The latter shows up the symmetry a lot more clearly - I've always hated >> having to write nested loops to express something flat. > > But there is no symmetry. Does it mean that there exists something in "a" > such that it's smaller than everything in "b", or that for everything in > "b" there exists a smaller thing in "a"? > > Well, for "<" it happens to be equivalent because "<" is transitive; it's > the same as a.min < b.min for non-empty "a" and "b". What about "!="? > Does any(1,2) != all(1,2)? No - this unrolls to [1,2].any? {|i| [1,2].all? {|j| i != j}} which is false. The symmetry is highlighted by the other way to unroll it: [1,2].all? {|j| [1,2].any? {|i| i != j}} i.e., there is no reason the LHS should be in the outer loop, rather than the RHS. My point was that the only reason there *was* an 'outer loop' was that the language forces you to write loops nestedly, whereas a cross product (essentially what this is) is flat. The only asymmetry involved is the fact that you have to keep the loop variables in their proper order with respect to the operator, function or whatever (not evident here because != is commutative). Also, any(1,2) != any(1,2) should be true. martin