This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Trouble understanding define (!)


Michael Livshin <mlivshin@bigfoot.com> writes:

> do extentions propagate back?  i.e.
> 
> -----------------------------------------------------------------
> ; module A
> (define-module (A))
> 
> (export grumble mumble)
> 
> (define-method grumble ((a <A>))
>   'grumble)
> 
> (define (mumble thing)
>   (grumble thing))
> 
> -----------------------------------------------------------------
> ; module B
> (define-module (B) :use-module (A))
> 
> (define-class <B> ...)
> 
> (define-method grumble ((b <B>))
>   'return-of-the-grumble)
> 
> (define grumble-result (mumble (make <B>)))
> -----------------------------------------------------------------
> 
> grumble-result should be 'return-of-the-grumble, but from the above
> paragraph it seems that it will be 'grumble.  what did I miss?

My explanation was quite sketchy.  B:grumble will be an
<extended-generic>.

(define-method generic-function-methods ((gf <extended-generic>))
  (remove-duplicates (flatten-generics gf)))

(define (flatten-generics gf)
  (apply append (methods gf) (map flatten-generics (generics gf))))

where methods and generics are selectors for the methods and generics
slots in <extended-generic>.

So, generic-function-methods will return both grumble methods in the
correct order, just as we wish.

> I'm still uncomfortable with the reliance on names, though...

We are only dependent upon name mappings provided by the module
system, just as usual.  The only "unusual" interaction with the module
system is that instead of querying for the existence of a name using
`defined?', we ask for the values of all bound variables with a given
name.

The effect is just what we want: instead of shadowing another GF with
the same name, there is a new GF created which contain the union of
methods.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]