From: Andy Wingo <wingo@pobox.com>
To: Jan Nieuwenhuizen <janneke@gnu.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: goops method defined only in derived classes fails to become generic?
Date: Sat, 21 May 2011 18:41:21 +0200 [thread overview]
Message-ID: <m3boywropa.fsf@unquote.localdomain> (raw)
In-Reply-To: <1296653688.19670.266.camel@vuurvlieg> (Jan Nieuwenhuizen's message of "Wed, 02 Feb 2011 14:34:48 +0100")
Hi,
On Wed 02 Feb 2011 14:34, Jan Nieuwenhuizen <janneke@gnu.org> writes:
> This worked with guile 1.8. Bug or feature?
Bugs, bugs, bugs! The files were:
> [5. text/x-scheme; base.scm]...
>
> (define-module (base)
> #:use-module (oop goops)
> #:export (<base>
> func))
>
> (define-class <base> ())
>
> (define-method (func (self <base>))
> (format #t "<base>: func\n"))
>
> [4. text/x-scheme; impl-a.scm]...
>
> (define-module (impl-a)
> #:use-module (oop goops)
> #:use-module (base)
> #:export (<impl-a>
> func-impl)
> #:re-export (func))
>
> (define-class <impl-a> (<base>))
>
> (define-method (func (self <impl-a>))
> (format #t "<impl-a>: func\n"))
>
> (define-method (func-impl (self <impl-a>))
> (format #t "<impl-a>: func-impl\n"))
>
> [3. text/x-scheme; impl-b.scm]...
>
> (define-module (impl-b)
> #:use-module (oop goops)
> #:use-module (base)
> #:export (<impl-b>
> func-impl)
> #:re-export (func))
>
> (define-class <impl-b> (<base>))
>
> (define-method (func (self <impl-b>))
> (format #t "<impl-b>: func\n"))
>
> (define-method (func-impl (self <impl-a>))
> (format #t "<impl-a>: func-impl\n"))
Note that here we have a typo I think (<impl-a> instead of <impl-b>);
this should not have worked in either, but it was working in 1.8 for a
reason I will get to in a minute.
> [2. text/x-scheme; use.scm]...
>
> #! /bin/sh
> # -*- scheme -*-
> exec guile --debug -L $(dirname $0) -s $0 "$@"
> !#
>
> (use-modules
> (oop goops)
> (base)
> (impl-a)
> (impl-b)
> )
>
> (define obj (make <impl-a>))
>
> (func obj)
>
> (func-impl obj)
This works in 1.8 because use-modules apparently has a bug in which
modules loaded from a use-modules form are loaded in reverse order. So
the last binding wins, and it's the one from <impl-a>. For some reason
the <impl-a> reference in the `func-impl' from impl-b.scm is never made;
I suspect related to some lazy expansion strangeness. This bug is not
present in 2.0.
Now, if we fix the bug in impl-b.scm to refer to <impl-b>, in 2.0 the
error is that `func-impl' does not apply to objects of type <impl-a>.
OK, this is correct. However, if instead of using use-modules we use
`define-module' with #:use-module forms, we meet a similar bug, in that
2.0's define-module imports the modules in reverse order, so we get the
`func-impl' from impl-a.scm, which does "work"; but wrongly!
Basically your test case had bugs, but they showed a very important bug
in guile 2.0's define-module, and a previously unknown one from 1.8.
I'm not going to fix 1.8, but I have fixed 2.0.
Thanks for the report,
Andy
--
http://wingolog.org/
next prev parent reply other threads:[~2011-05-21 16:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-02 13:34 goops method defined only in derived classes fails to become generic? Jan Nieuwenhuizen
2011-02-11 15:39 ` Andy Wingo
2011-02-11 18:49 ` Jan Nieuwenhuizen
2011-05-21 16:41 ` Andy Wingo [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-02-02 14:05 Jan Nieuwenhuizen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3boywropa.fsf@unquote.localdomain \
--to=wingo@pobox.com \
--cc=guile-devel@gnu.org \
--cc=janneke@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).