guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem merging generics across modules


From: David Pirotte
Subject: Re: Problem merging generics across modules
Date: Fri, 13 Oct 2017 12:14:30 -0300

Hi again,

> ... You should use #:re-export instead

Note that #:re-export fails if the name is not already defined ... which is ok 
for
small and individual projects, but less then optimal and subject to introduce 
bugs
for long term projects, involving multiple developers, with hundreds of 
modules, and
where module reorganization is (sometimes) part of the game ...  So I defined a 
macro
which checks if a name exists (as in imported) or not, and appropriately calls
export or re-export, that you should onlu use for getters, setters, accessors
and methods):

        
https://git.savannah.gnu.org/cgit/guile-cv.git/tree/cv/support/g-export.scm

Just as an example, your module definition would be (see below)... Then if this
module later imports another module, that defines !r, !g and/or !b, you still 
would
be fine...

Cheers,
David

;;;
;;; Extending equal?
;;;

(define-module (extending-equal)
  #:use-module (oop goops)
  ;; just changed the module 'path' to what ever ...
  #:use-module (g-export)

  #:export (<color>)

(g-export !r
            !g
            !b)

(define-class <color> ()
  (r #:accessor !r #:init-keyword #:r #:init-value 0)
  (g #:accessor !g #:init-keyword #:g #:init-value 0)
  (b #:accessor !b #:init-keyword #:b #:init-value 0))

(define-method (equal? (c1 <color>) (c2 <color>))
  (pk "in extended equal? ...")
  (and (= (!r c1) (!r c2))
       (= (!g c1) (!g c2))
       (= (!b c1) (!b c2))))

Attachment: pgp9uBClhGQNC.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]