[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[goops] adding a number class with generic methods
From: |
Marco Maggi |
Subject: |
[goops] adding a number class with generic methods |
Date: |
Tue, 2 May 2006 22:16:35 +0200 |
Hi,
I am trying to add a new number class, export generic
methods from a module and import them into another one. If I
ignore the GOOPS tutorial and read only the reference, it is
my understanting that I should do:
;; ----------------------------------------
;; exporting.scm
(define-module (gee gmp ompfr)
#:use-module (oop goops)
#:use-module (gee gmp mpfr))
(define-class <mpfr> (<number>)
(n #:init-value (real->mpfr 0) #:init-keyword #:value))
;; ... other stuff ...
(define-method (= (a <mpfr>) (b <mpfr>))
(mpfr-equal? (slot-ref a 'n) (slot-ref b 'n)))
(define-method (= (a <mpfr>) (b <real>))
(mpfr-equal? (slot-ref a 'n) (usable->mpfr b)))
(define-method (= (b <real>) (a <mpfr>))
(mpfr-equal? (slot-ref a 'n) (usable->mpfr b)))
(export =)
;; ----------------------------------------
;; importing.scm
(define-module (my-test)
#:use-module (mmg test dotest-1)
#:use-module (oop goops)
#:duplicates merge-generics
#:use-module (gee gmp ompfr))
(= #,(MPFR 2) #,(MPFR 2))
;; ----------------------------------------
but I get this error:
...
?: 6 (= #<<mpfr> 40351520> #<<mpfr> 403505e0>)
<unnamed port>: In expression (= #<<mpfr> 40351520> #<<mpfr>
403505e0>):
<unnamed port>: Unbound variable: =
If I read the tutorial it seems that I have to replace the
'(define-method (= ...' definitions with:
;; ----------------------------------------
(define-generic my=)
(let ((original= =))
(define-method (my= (a <number>) (b <number>))
(original= a b)))
(define-method (my= (a <mpfr>) (b <mpfr>))
(mpfr-equal? (slot-ref a 'n) (slot-ref b 'n)))
(define-method (my= (a <mpfr>) (b <real>))
(mpfr-equal? (slot-ref a 'n) (usable->mpfr b)))
(define-method (my= (b <real>) (a <mpfr>))
(mpfr-equal? (slot-ref a 'n) (usable->mpfr b)))
(set! = my=)
;; ----------------------------------------
but I get the same error.
I do not understand why the first solution does not work;
I've tried different combinations of functions but there is
something I am missing.
--
Marco Maggi
"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"
- [goops] adding a number class with generic methods,
Marco Maggi <=
- Re: [goops] adding a number class with generic methods, Marco Maggi, 2006/05/03
- Re: [goops] adding a number class with generic methods, Marco Maggi, 2006/05/04
- Re: [goops] adding a number class with generic methods, Mikael Djurfeldt, 2006/05/04
- Re: [goops] adding a number class with generic methods, Neil Jerram, 2006/05/06
- Re: [goops] adding a number class with generic methods, Mikael Djurfeldt, 2006/05/07
- Re: [goops] adding a number class with generic methods, Neil Jerram, 2006/05/07
- Re: [goops] adding a number class with generic methods, Ludovic Courtès, 2006/05/09
- Re: [goops] adding a number class with generic methods, Mikael Djurfeldt, 2006/05/09
- GOOPS and Code Complexity, Ludovic Courtès, 2006/05/09