unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: [goops] adding a number class with generic methods
@ 2006-05-04 19:13 Marco Maggi
  2006-05-04 19:26 ` Mikael Djurfeldt
  0 siblings, 1 reply; 11+ messages in thread
From: Marco Maggi @ 2006-05-04 19:13 UTC (permalink / raw)


"Neil Jerram" wrote:
>"Marco Maggi" <marco.maggi-ipsu@poste.it> writes:
> "marco.maggi-ipsu@poste.it" wrote:
>>  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.
>
> Damn... it seems to work if I do not EXPORT the generic
> methods.
>
>You mean if you remove the "(export =)" line?

Yes, with the following and no EXPORT invocation
it works.

(define-macro (make-comparison-operator class name func)
  `(begin
     (define-method (,name (a ,class) (b ,class))
       (,func (slot-ref a 'n) (slot-ref b 'n)))

     (define-method (,name (a ,class) (b <real>))
       (,func (slot-ref a 'n) (usable->mpfr b)))

     (define-method (,name (a <real>) (b ,class))
       (,func (usable->mpfr a) (slot-ref b 'n)))))

(make-comparison-operator <mpfr> = mpfr-equal?)


--
Marco Maggi




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [goops] adding a number class with generic methods
@ 2006-05-03  5:36 Marco Maggi
  2006-05-04  7:47 ` Neil Jerram
  0 siblings, 1 reply; 11+ messages in thread
From: Marco Maggi @ 2006-05-03  5:36 UTC (permalink / raw)


"marco.maggi-ipsu@poste.it" wrote:
>  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.

Damn... it seems to work if I do not EXPORT the generic
methods.

--
Marco Maggi




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread
* [goops] adding a number class with generic methods
@ 2006-05-02 20:16 Marco Maggi
  0 siblings, 0 replies; 11+ messages in thread
From: Marco Maggi @ 2006-05-02 20:16 UTC (permalink / raw)


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"



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-05-09  9:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-04 19:13 [goops] adding a number class with generic methods Marco Maggi
2006-05-04 19:26 ` Mikael Djurfeldt
2006-05-06 23:07   ` Neil Jerram
2006-05-07  9:37     ` Mikael Djurfeldt
2006-05-07 11:45       ` Neil Jerram
2006-05-09  7:56       ` Ludovic Courtès
2006-05-09  8:30         ` Mikael Djurfeldt
2006-05-09  9:43           ` GOOPS and Code Complexity Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2006-05-03  5:36 [goops] adding a number class with generic methods Marco Maggi
2006-05-04  7:47 ` Neil Jerram
2006-05-02 20:16 Marco Maggi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).