unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* contrib: goops doc: calling next-method
@ 2006-03-07 22:36 Marco Maggi
  2006-03-11 12:16 ` Neil Jerram
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Maggi @ 2006-03-07 22:36 UTC (permalink / raw)


Ciao,

  I propose the following to be appended to the
Next-method node in the GOOPS tutorial Texinfo.

@noindent
In the following example a class and a superclass define the
same
method:

@example
(use-modules (oop goops))

(define-class <a> ()
  one)

(define-class <b> (<a>)
  two)

(define-method (alpha (a <a>))
  "alpha a")

(define-method (alpha (b <b>))
  (list (next-method) "alpha b"))
@end example

@noindent
in the body of the @code{alpha<b>} function it is fine to invoke
@code{next-method} expecting it to invoke @code{alpha<a>}
because both
the @code{alpha} functions take the same number of
arguments. So the
result will be:

@example
(alpha (make <b>))
;; -> ("alpha a" "alpha b")
@end example

With the following definitions: the body of @code{alpha<b>}
invokes the
@code{alpha} function and an infinite loop will result:

@example
(define-method (alpha (b <b>))
  (list (alpha b) "alpha b"))
@end example

@noindent
the most specialised @code{alpha} function  is
@code{alpha<b>} itself.

With the following definitions:

@example
(use-modules (oop goops))

(define-class <a> ()
  one)

(define-class <b> (<a>)
  two)

(define-method (alpha (a <a>) c)
  (list "alpha a" c))

(define-method (alpha (b <b>))
  (list (next-method) "alpha b"))
@end example

@noindent
the code:

@example
(alpha (make <b>))
@end example

@noindent
will raise an error: the invocation of @code{alpha<b>} has
selected the
@code{alpha} functions that take only one parameter; the
invocation of
@code{next-method} in the body of @code{alpha<b>} will not
find any
other less specialised method; we will get an error even
with the
following:

@example
(define-method (alpha (b <b>))
  (list (next-method "string") "alpha b"))
@end example


It is possible to invoke @code{alpha<a>} by evaluating the
@code{alpha}
variable directly, with the appropriate number of parameters:

@example
(define-method (alpha (b <b>))
  (list (alpha b "string") "alpha b"))

(alpha (make <b>))
;; -> (("alpha a" "string") "alpha b")
@end example



--
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


^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: contrib: goops doc: calling next-method
@ 2006-03-12  6:09 Marco Maggi
  0 siblings, 0 replies; 3+ messages in thread
From: Marco Maggi @ 2006-03-12  6:09 UTC (permalink / raw)


Neil Jerram wrote:
> What do you think about the following revision of
> the Next-method node?  Does it cover everything
> that you wanted to cover?

Yes. I would not exclude the examples though.
I often have problems with words, no matter how clear
they are; with enough examples I can understand 80%
almost immediately.

  Examples is what I look for in tutorials; maybe
other novices (the tutorial audience) on this list
may step in and say what they think.

Thank You.




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-03-12  6:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-07 22:36 contrib: goops doc: calling next-method Marco Maggi
2006-03-11 12:16 ` Neil Jerram
  -- strict thread matches above, loose matches on Subject: below --
2006-03-12  6:09 Marco Maggi

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).