From e672dd0208c46d0ce37cdd8d92e129ea5360baf7 Mon Sep 17 00:00:00 2001 From: Mikael Djurfeldt Date: Thu, 17 Apr 2003 18:47:18 +0000 Subject: [PATCH] * goops.scm (equal?): Provide default method for `equal?'. (compute-getters-n-setters): Check for bad init-thunks. * eq.c (scm_eqv_p, scm_equal_p): Turned into a primitive generics. * goops.texi (Object Comparisons): Removed object-eqv? and object-equal? and added eqv?, equal? and =. --- NEWS | 4 ++-- doc/goops/ChangeLog | 5 +++++ doc/goops/goops.texi | 31 ++++++++++++++++++++++--------- libguile/ChangeLog | 2 +- libguile/eq.c | 7 +++++-- oop/goops.scm | 3 ++- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 94b48bf0e..86b6047c9 100644 --- a/NEWS +++ b/NEWS @@ -56,10 +56,10 @@ methods from their accessors. This makes the metaclass in (oop goops active-slot) working again. -** equal? is now a primitive generic +** eqv? and equal? are now primitive generic functions This means that it is possible to provide custom comparisons for new -classes by specializing `equal?' to those classes. +classes by specializing `eqv?' and `equal?' to those classes. * Changes to the C interface diff --git a/doc/goops/ChangeLog b/doc/goops/ChangeLog index 44fb04b4a..36a6d1c3c 100644 --- a/doc/goops/ChangeLog +++ b/doc/goops/ChangeLog @@ -1,3 +1,8 @@ +2003-04-17 Mikael Djurfeldt + + * goops.texi (Object Comparisons): Removed object-eqv? and + object-equal? and added eqv?, equal? and =. + 2002-11-08 Neil Jerram * goops.texi (Top): Say "Indices" before index nodes in main menu. diff --git a/doc/goops/goops.texi b/doc/goops/goops.texi index 9cc07d652..7b5aa0e7c 100644 --- a/doc/goops/goops.texi +++ b/doc/goops/goops.texi @@ -26,7 +26,7 @@ Guile @ifinfo This file documents GOOPS, an object oriented extension for Guile. -Copyright (C) 1999, 2000, 2001 Free Software Foundation +Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -2372,17 +2372,30 @@ as done by @code{scm-error}. @node Object Comparisons @subsection Object Comparisons -@deffn generic object-eqv? -@deffnx method object-eqv? ((x ) (y )) -@deffnx generic object-equal? -@deffnx method object-equal? ((x ) (y )) +@deffn generic eqv? +@deffnx method eqv? ((x ) (y )) +@deffnx generic equal? +@deffnx method equal? ((x ) (y )) +@deffnx generic = +@deffnx method = ((x ) (y )) Generic functions and default (unspecialized) methods for comparing two GOOPS objects. -The default methods always return @code{#f}. Application class authors -may wish to define specialized methods for @code{object-eqv?} and -@code{object-equal?} that compare instances of the same class for -equality in whatever sense is useful to the application. +The default method for @code{eqv?} returns @code{#t} for all values +that are equal in the sense defined by R5RS and the Guile reference +manual, otherwise @code{#f}. The default method for @code{equal?} +returns @code{#t} or @code{#f} in the sense defined by R5RS and the +Guile reference manual. If no such comparison is defined, +@code{equal?} returns the result of a call to @code{eqv?}. The +default method for = returns @code{#t} if @var{x} and @var{y} are +numerically equal, otherwise @code{#f}. + +Application class authors may wish to define specialized methods for +@code{eqv?}, @code{equal?} and @code{=} that compare instances of the +same class for equality in whatever sense is useful to the +application. Such methods will only be called if the arguments have +the same class and the result of the comparison isn't defined by R5RS +and the Guile reference manual. @end deffn @node Cloning Objects diff --git a/libguile/ChangeLog b/libguile/ChangeLog index bedd678fd..79fb5d875 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,6 +1,6 @@ 2003-04-17 Mikael Djurfeldt - * eq.c (scm_equal_p): Turned into a primitive generic. + * eq.c (scm_eqv_p, scm_equal_p): Turned into a primitive generics. * snarf.h (SCM_PRIMITIVE_GENERIC, SCM_PRIMITIVE_GENERIC_1): New macros. diff --git a/libguile/eq.c b/libguile/eq.c index d26a89ad3..8f4512d7d 100644 --- a/libguile/eq.c +++ b/libguile/eq.c @@ -67,7 +67,7 @@ SCM_DEFINE1 (scm_eq_p, "eq?", scm_tc7_rpsubr, #undef FUNC_NAME -SCM_DEFINE1 (scm_eqv_p, "eqv?", scm_tc7_rpsubr, +SCM_PRIMITIVE_GENERIC_1 (scm_eqv_p, "eqv?", scm_tc7_rpsubr, (SCM x, SCM y), "The @code{eqv?} procedure defines a useful equivalence relation on objects.\n" "Briefly, it returns @code{#t} if @var{x} and @var{y} should normally be\n" @@ -110,7 +110,10 @@ SCM_DEFINE1 (scm_eqv_p, "eqv?", scm_tc7_rpsubr, && SCM_COMPLEX_IMAG (x) == SCM_COMPLEX_IMAG (y)); } } - return SCM_BOOL_F; + if (SCM_UNPACK (g_scm_eqv_p)) + return scm_call_generic_2 (g_scm_eqv_p, x, y); + else + return SCM_BOOL_F; } #undef FUNC_NAME diff --git a/oop/goops.scm b/oop/goops.scm index 04e900216..574975575 100644 --- a/oop/goops.scm +++ b/oop/goops.scm @@ -658,7 +658,8 @@ ;;; Methods to compare objects ;;; -(define-method (equal? x y) #f) +(define-method (eqv? x y) #f) +(define-method (equal? x y) (eqv? x y)) ;;; These following two methods are for backward compatibility only. ;;; They are not called by the Guile interpreter.