http://www.jsoftware.com/jwiki/Essays/The%20TAO%20of%20J
le=: 0 1 -: /:@,&< ge=: 0 1 -: \:@,&< compare=: ge - le 'abc' compare 'def' _1 'Roger' compare 'Ken' 1 3 4 compare 3 4 5 _1 3 4 compare 3 1 4 1 5 9 1 3 4 compare 3 4 0 On Sun, Oct 30, 2011 at 1:29 PM, Andrew Pennebaker <[email protected]> wrote: > Is there a dyad that returns -1 for string x less than string y, 1 for x > greater than y, and 0 for x equals y? > > -: Almost does this, but it only tests equality; it's not specific enough > to tell you whether x or y is greater. Instead it just returns 0 for not > equal and 1 for equal. > > The compare dyad almost does this, but with an API with complexity on the > order of diff or subversion. > > 'abc' compare 'def' > 0 [0] abc > 1 [0] def > > 'abc' compare 'abc' > no difference > > In a conditional you would have to use (('abc' compare 'abc') compare 'no > difference') compare 'no difference' ad infinitum just to see if there was > 'no difference' in the original compare! > > Cheers, > > Andrew Pennebaker > www.yellosoft.us > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
