guile-user
[Top][All Lists]
Advanced

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

Re: guile-1.5.1 and deprecated ...


From: Marius Vollmer
Subject: Re: guile-1.5.1 and deprecated ...
Date: 22 Aug 2001 22:41:51 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102

Rob Browning <address@hidden> writes:

> I think perhaps we should move this over to devel since it seems like
> an issue we need to address before the stable release.  While the new
> behavior makes sense for normal procedures, it may not for methods.

This is not really a new behavior.  I think the module system /
generic function interaction always worked the same, but it might be
that the recent export/re-export cleanup prohibits some things to work
that did work (but mostly by accident).

In a case like this:

    (define-module (a)
      :use-module (oop goops))

    (define-method (foo (o <vector>))
      (display "VETCOR: ") (display o) (newline))

    (export foo)


    (define-module (b)
      :use-module (oop goops))

    (define-method (foo (o <list>))
      (display "LIST: ") (display o) (newline))

    (export foo)

two modules export a variable under the name "foo" that happen to
start out with a generic function as their value.

It is not clear whether the user wants only one generic function, or
to two distinct ones.  Sometimes you might want the former, but the
way the module system works (now and before the export/re-export
cleanup), you get two distinct variables with two distince generic
functions as their value.

When you use both module (a) and module (b), you only get one of them.
Right now, you don't get a warning or error about the fact that you
imported two variables under the same name, but in the future, this
will very likely be flagged at the time you first use "foo".

By using the `:select' option of `:use-module', you can import the two
variables without a name conflict.


If you want there to be only one variable, you must express that
explicitely, by defining it only once.  (This is obscured since
`define-method' might either act as a definition, or as a mere
augmentation of an existing generic function.  It will be a definition
when no variable is visible under the given name.  In that case, it
will define such a variable, and initialize it with a new generic
function.)

Thus, you can write

    (define-module (a)
      :use-module (oop goops))

    (define-method (foo (o <vector>))
      (display "VETCOR: ") (display o) (newline))

    (export foo)


    (define-module (b)
      :use-module (oop goops)
      :use-module (a))  ;; this makes "foo" visible.

    ;; this adds to the generic function in "foo".
    (define-method (foo (o <list>))
      (display "LIST: ") (display o) (newline))


Using `(export foo)' in module (b) would be wrong, since (b) does not
contain a definition for "foo".  You could use `(re-export foo)' to
make the "foo" from (a) visible to users of (b).  Whether to do this
is a matter of interface design.  I would find it plausible to require
users to use the (a) module if they want to use one of the protocols
associated with the classes defined by (a).


One could also take the modularization a step further and put the
protocol into its own module:

    (define-module (protocol-foo)
      :use-module (oop goops))

    (export foo)

    ;; Calling `(foo OBJ)' displays OBJ prefixed by a string
    ;; determined by the type of OBJ.
    ;;
    (define-generic foo)

    (define-module (a)
      :use-module (oop goops)
      :use-module (protocol-foo))

    ;; Make vectors speak the foo protocol.
    ;;
    (define-method (foo (o <vector>))
      (display "VETCOR: ") (display o) (newline))


    (define-module (b)
      :use-module (oop goops)
      :use-module (protocol-foo))

    ;; Make lists speak the foo protocol
    ;;
    (define-method (foo (o <list>))
      (display "LIST: ") (display o) (newline))

Now, (a) and (b) don't export anything, and are only needed to
integrate new methods into the system.



reply via email to

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