unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Marco Maggi" <marco.maggi-ipsu@poste.it>
Subject: [goops] adding a number class with generic methods
Date: Tue,  2 May 2006 22:16:35 +0200	[thread overview]
Message-ID: <IYNMZN$2BE31EEE8FBB61C41EBEA83EE5930024@poste.it> (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


             reply	other threads:[~2006-05-02 20:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-02 20:16 Marco Maggi [this message]
  -- 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-04 19:13 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='IYNMZN$2BE31EEE8FBB61C41EBEA83EE5930024@poste.it' \
    --to=marco.maggi-ipsu@poste.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).