[racket-dev] Comparison functions and the `data' collection

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Jun 22 11:19:54 EDT 2012

Yesterday, David Van Horn wrote:
> I think {-1,0,1} is the worst of all worlds.  I prefer the more
> lenient approach of allowing any number[*].  This follows the Lisp
> tradition of returning "more than just the truth", since a
> comparison can also convey the difference between the arguments; in
> other words `-' is a comparison function, which is the trick I use
> to remember how to interpret the result of compare functions in
> Java, for example.

That's some of the reason that it's my preference.  But when I
considered the different choices, I went further: it's not *just* the
use of `-' which makes it a natural choice -- it's the fact that very
often when you're dealing with comparators there's a meaning for the
distance between two inputs.  For example, when you're dealing with
just positive/0/negative results, you can very easily create
combinations of comparison functions from existing ones by summing
them, or even by throwing multipliers for int input comparators so you
get preferences.  (Concrete case: if the doc lookup functionality uses
sorting, then it's much easier to combine different inputs with
different weights when you have just numbers, in contrast to juggling
symbolic results.)

> If we really want to break tradition by restricting to "just the
> truth" (a three-valued function), meaningful symbols is my
> preference over {-1,0,1}.

I don't think that they're completely useless -- you still get some of
the benefits of dealing with numbers, like negating the results.

But in any case, my point was that we currently have a choice that is
used in practically no other place, which makes it a bad one.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.