[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] R7RS-large comparators



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 16-07-13 15:03, Alexey Radul wrote:
> On Tue, Jul 16, 2013 at 3:19 AM, Marijn <hkBst@x> wrote:
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>> 
>> On 16-07-13 06:21, Alexey Radul wrote:
>>> In addition to the weight of tradition, -1, 0, and 1 have the 
>>> benefit of being naturally correctly totally-ordered amongst 
>>> themselves. Semantically chosen symbols are unlikely to share
>>> this advantage.
>> 
>> What exactly is ``naturally correct'' about this inherited total 
>> ordering?
> 
> Precisely that any currying of (the second argument of) any
> compare procedure becomes a homomorphism of totally ordered sets.
> 
>> Do you also think  (< (< 0 1) (< 1 0))  should be #t or #f?
> 
> That example is irrelevant, but (let ((<=>
> (comparator-compare-procedure integer-comparator))) (< (<=> -2 0)
> (<=> 2 0))) absolutely should return #t.

   (let ((<=> (comparator-compare-procedure integer-comparator)))
     (< (<=> 1 0) (<=> 2 0)))

shows that this is not a homomorphism, since (< 1 2) is true (or LT or
- -1), but (< 0 0) is false (or EQ or 0).  Unless you meant homomorphism
differently?

Marijn

>> If we could compare functions for equality, we could have the
>> return values be the respective equivalents of <, > and =.
>> Failing that maybe '<, '> and '= would be appropriate?
> 
> I like Haskell's choice of a new, disjoint type for the answers of 
> compare.  In Scheme, however, such a thing adds considerable extra 
> weight, so I am not even sure I would support it.  In addition to 
> being traditional (and therefore quite recognizable), integers
> have the (debatable) advantage over symbols of allowing comparator
> puns, such as (define (abs x) ; Look Ma, no branch! (* x
> ((comparator-compare-procedure real-comparator) 0))) which may even
> be important numerical computations.

I don't think multiplication is a very efficient way of implementing
the absolute value function; an implementation could just fix the sign
bit directly.  But if there are other reasons for such traditional
compare procedures, then they can exist separately from the default
compare procedures.

Marijn
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlHmUecACgkQp/VmCx0OL2xFNACgyJkHvzEx2kvTkXVLw3q1xnck
+BcAoIZCMSbzEb0DoH5tlsohn4ELgp7l
=E5d4
-----END PGP SIGNATURE-----

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports