On Thursday 09 June 2005 12:21, John Macdonald wrote: > On Thu, Jun 09, 2005 at 06:41:55PM +0200, "TSa (Thomas Sandla �" wrote: > > Edward Cherlin wrote: > > >That means that we have to straighten out the functions > > > that can return either a Boolean or an item of the > > > argument type. Comparison functions < > <= >= = != should > > > return only Booleans, > > > > I'm not sure but Perl6 could do better or at least trickier > > ;) Let's assume that < > <= >= when chained return an > > accumulated boolean and the least or greatest value where > > the condition was true. E.g. > > > > 0 < 2 < 3 returns 0 but true > > > > 1 < 2 < 1 returns 1 but false > > > > 4 < 5 < 2 returns 2 but false > > > > Then the reduce versions [<] and [<=] naturally come out as > > min and strict min respectively. > > > > Is it correct that [min] won't parse unless min is declared > > as an infix op, which looks a bit strange? > > > > if 3 min 4 { ... }
That's how it was done in APL. In fact, that's how every dyadic (two-argument) function was done in APL. It looks strange at first, but the syntax is simpler. "I eat my peas with honey. I've done it all my life. It makes them taste real funny, But it keeps them on the knife." > The natural method of implementation would imply that the > final is returned: > > 0 < 2 < 3 returns 3 but true > > 1 < 2 < 1 returns 1 but false > > 4 < 5 < 2 returns 2 but false > > The application of each stage of the chain has to remember > the right hand value (for the next stage of the comparison) > as well as the accumulated boolean result. When the boolean > result is true, that has < and <= returning the max, and > and > > >= returning the min - the opposite of what you asked above. In J one can do (<)/ 0 1 1, evaluated as 0<(1<1) 0<0 0 Then, since 0<0 is 0, and 0<1 is 1, 0 is a left identity of < (restricted to Booleans), and </'' is defined to be 0. I don't suppose anybody here cares, but it turns out that Boolean scans have a variety of uses, such as running parity, locating transitions, and Gray Code to binary conversion, and Boolean identity elements have their uses within these schemes. -- Edward Cherlin Generalist & activist--Linux, languages, literacy and more "A knot! Oh, do let me help to undo it!" --Alice in Wonderland http://cherlin.blogspot.com