From: David Pirotte <david@altosw.be>
To: "Kovacsics Róbert" <kovirobi@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: Modules and GOOPS
Date: Thu, 28 Jul 2016 18:14:25 -0300 [thread overview]
Message-ID: <20160728181425.5f167237@capac> (raw)
In-Reply-To: <CABPkNKmRUQ2WhdZoJgkxSquMSVVQRLEQ5WXEsnx0gKVbA4ArvA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4451 bytes --]
Hello,
Before anything else, note that I speak on my own behalf here, not in the name of
Guile. I'm saying this because I have an opinionated opinion about Goops, its actual
'design/problems/limitations/bugs' [depending of your point of view], why and how we
should change this, as well as how users should use it, precisely regarding, but not
limited to, generic functions and the module system, among other things.
> I have trouble with getting GOOPS and modules to co-operate. What I am
> trying to do is to have 'A subclass B' where A is something akin to an
> abstract class, that is it has generic "x" for which it provides no
> implementation. This is my minimum broken example:
First, generic functions are 'containers', that are not associated, and do not
pertain to any class. <a> does not have a generic function x:
obviously, this _is_ the beauty (and one of the reason why it's been design
this way) since this way, the entire knowledge, except for slot-ref and
slot-set! [1] of a generic function multi method polymorphic dispatch system
is in user methods and procedures called by these methods;
this means, unlike it's been said on this ML several time, unless you use
slot-set! (same for Guile set!, no diff wrt Goops here) and class
redefinition, Goops is perfectly 'compatible' with functional programming;
[1] same problem for define-record, which are not more neither less
'functional' then Goops, imo.
Then unlike you've been told by others, I do not recommend to define generic
function, they are just 'containers', the system creates them for you and it is an
error [not implemented by Guile] to redefine a generic function. With the last in
mind, manually defining GF will work if you play with a couple of your own modules,
but it will almost certainly fail for large system.
But if you do so, define generic functions manually, then I recommend do it in
another module.
> ; <mbe/a.scm>=
> (define-module (mbe a)
> #:use-module (oop goops)
> #:export (<a> x y))
>
> (define-class <a> ())
>
> (define-generic x)
> (define-generic y)
>
> (define-method (y (a <a>))
> (display (x a)))
>
> ; <mbe/b.scm>=
> (define-module (mbe b)
> #:use-module (oop goops)
> #:use-module (mbe a)
> #:export (<b> x))
It will work if you #:re-export (x):
#:export (<b>)
#:re-export (x))
But that not good enough, imo. We precisely _do not_ want to know if we have to use
#:export or #:re-export, what we want here is the system to do that for us. I wrote
a macro which does the check 'if-exists' for us and either #:export or #:re-export
adequately, it's here, fell free to use it:
http://git.savannah.gnu.org/cgit/grip.git/tree/grip/g-export.scm
You should use it _only_ for getters, setters, accessors and methods, obviously!
here is an example of use
http://git.savannah.gnu.org/cgit/grip.git/tree/grip/clutter/grid.scm
Make sure your class names are unique i the entire 'system' and always use #:export
<class name>: this will always create a fresh new binding, and so, unlike in CLOS,
won't trigger a class redefinition if it would need to. This said, unless you
really know what you're doing, or for pure experimental reasons, don't write
'production' code that rely on class redefinition.
> (define-class <b> (<a>))
>
> (define-method (x (b <b>))
> 'b)
>
> ; <mbe/test.scm>=
> (define-module (mbe test)
> #:use-module (oop goops)
> #:use-module (mbe a)
> #:use-module (mbe b)
> #:duplicates (merge-generics))
You should add merge-generics to the default handlers:
scheme@(guile-user)> (default-duplicate-binding-handler)
$5 = (replace warn-override-core warn last)
So you'd have
#:duplicates (merge-generics replace warn-override-core warn last)
Note that you still have to set these in your repl (and any script of yours), if you
import more then 1 module defining a GF. Here is an example of script:
http://git.savannah.gnu.org/cgit/grip.git/tree/grip/clutter/examples/bouncer.in
[ line 38 - 41
Also note that in Guile-2.0, module definitions (ice-9/boot.scm
define-modules* macro) were calling (default-duplicate-binding-handler), so it
was not necessary to declare #:duplicates in each module. This great global
parameter setting, and API IMO, has been withdrawn in Guile-2.2, which hard codes
duplicate handlers 'as in the manual'.
David.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2016-07-28 21:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-27 17:53 Modules and GOOPS Kovacsics Róbert
2016-07-27 19:44 ` Jan Wedekind
2016-07-28 22:36 ` David Pirotte
2016-07-28 21:14 ` David Pirotte [this message]
2016-07-29 5:17 ` David Pirotte
2016-07-29 17:00 ` Kovacsics Róbert
2016-07-29 18:00 ` Marko Rauhamaa
2016-07-31 3:59 ` David Pirotte
2016-07-31 10:44 ` Chris Vine
2016-07-31 16:38 ` Marko Rauhamaa
2016-07-31 2:35 ` David Pirotte
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=20160728181425.5f167237@capac \
--to=david@altosw.be \
--cc=guile-user@gnu.org \
--cc=kovirobi@gmail.com \
/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).