From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: doc eq? eqv? equal? Date: Thu, 02 Sep 2004 11:24:34 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87oekplay5.fsf@zip.com.au> References: <87r7q2a9c8.fsf@zip.com.au> <87y8k80wg6.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1094088336 10342 80.91.224.253 (2 Sep 2004 01:25:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 2 Sep 2004 01:25:36 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Sep 02 03:25:25 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C2gLr-0004SX-00 for ; Thu, 02 Sep 2004 03:25:23 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C2gQl-0007DQ-28 for guile-devel@m.gmane.org; Wed, 01 Sep 2004 21:30:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C2gQe-0007DL-RB for guile-devel@gnu.org; Wed, 01 Sep 2004 21:30:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C2gQd-0007D9-UH for guile-devel@gnu.org; Wed, 01 Sep 2004 21:30:20 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C2gQd-0007D6-Qy for guile-devel@gnu.org; Wed, 01 Sep 2004 21:30:19 -0400 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1C2gLU-0005LP-DK for guile-devel@gnu.org; Wed, 01 Sep 2004 21:25:01 -0400 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i821Otje015813 for ; Thu, 2 Sep 2004 11:24:55 +1000 Original-Received: from localhost (ppp2B3A.dyn.pacific.net.au [61.8.43.58]) by mailproxy1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i821OrlY001814 for ; Thu, 2 Sep 2004 11:24:53 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1C2gL8-0000Hn-00; Thu, 02 Sep 2004 11:24:38 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:4068 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4068 New words about eq? etc. I dropped the bit in eqv about "left slightly open to interpretation", which doesn't really seem right in my reading of the r5rs. My reading is that literals and indistinguishable procedures may or may not be eqv, but that's the limit of the flexibility, at least as far as the standard types go. 3.1.2 Equality -------------- There are three kinds of core equality predicates in Scheme, described below. The same kinds of comparison arise in other functions, like `memq' and friends (*note List Searching::). For all three tests, objects of different types are never equal. So for instance a list and a vector are not `equal?', even if their contents are the same. Exact and inexact numbers are considered different types too, and are hence not equal even if their values are the same. `eq?' tests just for the same object (essentially a pointer comparison). This is fast, and can be used when searching for a particular object, or when working with symbols or keywords (which are always unique objects). `eqv?' extends `eq?' to look into the value of numbers and characters. It can for instance be used somewhat like `=' (*note Comparison::) but without an error if one operand isn't a number. `equal?' goes further, it looks (recursively) into the contents of lists, vectors, etc. This is good for instance on lists that have been read or calculated in various places and are the same, just not made up of the same pairs. Such lists look the same (when printed), and `equal?' will consider them the same. -- Scheme Procedure: eq? x y -- C Function: scm_eq_p (x, y) Return `#t' if X and Y are the same object, except for numbers and characters. For example, (define x (vector 1 2 3)) (define y (vector 1 2 3)) (eq? x x) => #t (eq? x y) => #f Numbers and characters are not equal to any other object, but the problem is they're not necessarily `eq?' to themselves either. This is even so when the number comes directly from a variable, (let ((n (+ 2 3))) (eq? n n)) => *unspecified* Generally `eqv?' below should be used when wanting to compare numbers or characters. `=' (*note Comparison::) or `char=?' (*note Characters::) can be used too. It's worth noting that end-of-list `()', `#t', `#f', a symbol of a given name, and a keyword of a given name, are unique objects. There's just one of each, so for instance no matter how `()' arises in a program, it's the same object and can be compared with `eq?', (define x (cdr '(123))) (define y (cdr '(456))) (eq? x y) => #t (define x (string->symbol "foo")) (eq? x 'foo) => #t -- C Function: int scm_is_eq (SCM x, SCM y) Return `1' when X and Y are equal in the sense of `eq?', otherwise return `0'. The `==' operator should not be used on `SCM' values, an `SCM' is a C type which cannot necessarily be compared using `==' (*note The SCM Type::). -- Scheme Procedure: eqv? x y -- C Function: scm_eqv_p (x, y) Return `#t' if X and Y are the same object, or for characters and numbers the same value. On objects except characters and numbers, `eqv?' is the same as `eq?' above, it's true if X and Y are the same object. If X and Y are numbers or characters, `eqv?' compares their type and value. An exact number is not `eqv?' to an inexact number (even if their value is the same). (eqv? 3 (+ 1 2)) => #t (eqv? 1 1.0) => #f -- Scheme Procedure: equal? x y -- C Function: scm_equal_p (x, y) Return `#t' if X and Y are the same type, and their contents or value are equal. For a pair, string, vector or array, `equal?' compares the contents, and does so using using the same `equal?' recursively, so a deep structure can be traversed. (equal? (list 1 2 3) (list 1 2 3)) => #t (equal? (list 1 2 3) (vector 1 2 3)) => #f For other objects, `equal?' compares as per `eqv?' above, which means characters and numbers are compared by type and value (and like `eqv?', exact and inexact numbers are not `equal?', even if their value is the same). (equal? 3 (+ 1 2)) => #t (equal? 1 1.0) => #f Hash tables are currently only compared as per `eq?', so two different tables are not `equal?', even if their contents are the same. `equal?' does not support circular data structures, it may go into an infinite loop if asked to compare two circular lists or similar. New application-defined object types (*note Defining New Types (Smobs)::) have an `equalp' handler which is called by `equal?'. This lets an application traverse the contents or control what is considered `equal?' for two objects of such a type. If there's no such handler, the default is to just compare as per `eq?'. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel