guile-devel
[Top][All Lists]
Advanced

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

Re: Help required with exporting and using GOOP generics


From: Mark H Weaver
Subject: Re: Help required with exporting and using GOOP generics
Date: Thu, 14 Mar 2013 17:42:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Hi Brent,

Brent Pinkney <address@hidden> writes:
> I am having serious problems exporting generics from subclasses of
> <object> and then using them in other modules.

Apologies for the confusion.  You're not the only one who's been having
trouble with this.  There *is* a proper solution, which I will describe
below, but clearly this issue needs to be discussed in the manual, and
we should probably add some compiler warnings as well.

The root of the problem is that GOOPS automatically defines generic
functions whenever you add a method to a generic that does not exist.
IMO, this was a serious design error, made many years ago.  It was done
in the name of convenience, but has caused enormous confusion over the
years.  It is best to *never* rely on this automatic behavior.

The proper solution is as follows:

* Every generic function must be defined (using 'define-generic') and
  exported from one (and only one) module.

* Every module that uses a generic function, or adds a method to it (and
  that includes slot accessors), must first import the generic function
  from the (one) module that exports it.

Think of a generic function as a normal procedure that contains an
internal table of methods.  Like any other procedure, there's a single
module that defines it and exports it.  The fact that some modules add
methods to these internal tables does not mean that it is appropriate to
export the procedure from those other modules.

Hope this helps,

      Mark



reply via email to

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