Ray Dillinger scripsit: > eq's behavior is strictly less specified than eqv?s behavior. > That means it is LESS discriminating, not more discriminating.
It is more discriminating in the same sense that eqv? is more discriminating than equal?, namely that it can distinguish between a 2 and another 2, whereas eqv? cannot. By the same token, (a b c) and (a b c) are not eqv? (in general), but they are equal?, because equal? is less discriminating than eqv?. "Why, can you imagine what would happen if we named all the twos Henry or George or Robert or John or lots of other things? You'd have to say Robert plus John equals four, and if the four's name were Albert, things would be hopeless." --The Magic Tollbooth That is exactly the distinction that eq? can make: it can distinguish between Robert and John even though they are both 2. > In fact, every instance of reliance on such a false > "distinction" (one made by eq? but not eqv?) is necessarily > either a bug, or implementation-dependent code. This reduces > eq? to the status of an implementation-dependent performance > hack rather than a properly specified language feature. True. However, if you know you are comparing eq?-safe types, you can use eq? and eliminate the type tests. > I invite people to make the following test. The following raises > an exception whenever eq? is used in a context where its return > value is unspecified. Type in > > (define (eq? arg1 arg2) > > (cond ((not (eqv? arg1 arg2)) #f) > ((or (symbol? arg1) (pair? arg1) > (boolean? arg1) (procedure? arg1)) #t) > ((and (vector? arg1) (> (vector-length arg1) 0)) #t) > ((and (string? arg1) (> (string-length arg1) 0)) #t) > (else (raise "eq? used incorrectly"))) This only works if you have no non-R5RS types in your program. -- John Cowan <[email protected]> http://www.ccil.org/~cowan Today an interactive brochure website, tomorrow a global content management system that leverages collective synergy to drive "outside of the box" thinking and formulate key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. --Alex Papadimoulis _______________________________________________ Scheme-reports mailing list [email protected] http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports
