From: Ken A. <kan...@bb...> - 2004-06-18 14:31:16
|
object equality is one of those things that seem like it should be simple, but it gets pretty complicated after you think about it, especially if you thinking about it in terms of parallel or distributed computation. Here's a nice paper by Henry Baker about equality: http://home.pipeline.com/~hbaker1/ObjectIdentity.html What it means to copy an object is another example. Scheme has 4 equality procedures eq? eqv? = and equal? while Java has only = and .equals. If you only want to use only 2 procedures, use eqv? and equal?. Here's what http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_idx_216 says about eqv?: Briefly, it returns #t if obj1 and obj2 should normally be regarded as the same object. This relation is left slightly open to interpretation, but the following partial specification of eqv? holds for all implementations of Scheme. There's a lot of wiggle room to allow different Schemes to have different implementation choices. For example, in a C based implementation of Scheme low order bits (typically) are used for type information so objects like small integers, small floats, characters ... can be implemented as one word "objects", rather than a pointer to memory. In JScheme, every object is a Java object, but some objects like ascii characters and small integers are cached so eq? may seem to work when you really should be using eqv?. One difference between JScheme and other Schemes is that literal strings are eq? following Java semantics. Also, simple tests can full you, so for example (eq? 3 3) may return #t but (eq? 123456789 123456789) may return #f. One nice thing you can do in Common Lisp is create a hashtable and give it the equality operator to use. Java only provides .equals HashTables and HashSets. k At 11:02 AM 6/17/2004 -0400, Geoffrey Knauth wrote: >Never mind. I should have tried eqv? too. For the record: > >JScheme: >(eq? 128 128) => #f ;; 2^8 >(eq? 127 127) => #t >(eqv? 128 128) => #t > >PLT Scheme v207: >(eq? 1073741824 1073741824) => #f ;; 2^30 >(eq? 1073741823 1073741823) => #t >(eqv? 1073741824 1073741824) => #t > >Geoffrey >-- >Geoffrey S. Knauth | http://knauth.org/gsk > >On Jun 17, 2004, at 06:50, Geoffrey Knauth wrote: > >>I ran into this while calculating azimuths. >> >>> (eq? 180 180) >>#f >>> (= 180 180) >>#t >>> (eq? 0 0) >>#t >>> (eq? 1 1) >>#t >>> (eq? 2 2) >>#t >>> (eq? 3 3) >>#t >>> (eq? 180 180) >>#f >> >>After poking around, I found this: >> >>> (eq? 127 127) >>#t >>> (eq? 128 128) >>#f >>> (eq? -127 -127) >>#t >>> (eq? -128 -128) >>#f >> >>For now I'll use = instead of eq?. I was just wondering if this was documented. >> >>Geoffrey >>-- >>Geoffrey S. Knauth | http://knauth.org/gsk >> >> >> >>------------------------------------------------------- >>This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference >>Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer >>Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA >>REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND >>_______________________________________________ >>Jscheme-devel mailing list >>Jsc...@li... >>https://lists.sourceforge.net/lists/listinfo/jscheme-devel > > > >------------------------------------------------------- >This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference >Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer >Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA >REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND >_______________________________________________ >Jscheme-devel mailing list >Jsc...@li... >https://lists.sourceforge.net/lists/listinfo/jscheme-devel |