From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: guile-devel@gnu.org
Cc: David Pirotte <david@altosw.be>
Subject: Re: goops - accessors, methods and generics
Date: Sat, 23 Feb 2013 12:20:30 +0100 [thread overview]
Message-ID: <3870635.z0WUZy3jFd@warperdoze> (raw)
In-Reply-To: <20130221195139.59f41d13@capac>
I don't find the behavior strange.
1. Declaring dialog generic in mg-1 and mg-2 and merge generics in
mg-3 solves the mg-3 case.
2. When exporting dialog in mg-4 the system automatically undefine the
dialog symbol imported. By in stead using :re-export (dialog) the mg-4
case
is solved.
The question if we should automatically always merge generics and
automatically always define accessors generic I do not agree. The
reason is that the current approach is more general. On the other hand
as we saw subtle bugs can appear and a good warning/diagnosing system
that can help pinpoint these issues would indeed be a good additions.
/Stefan
On Thursday, February 21, 2013 07:51:39 PM David Pirotte wrote:
> Hello all,
>
> given the following 4 modules, I am facing what I consider an
> inconsistent goops behavior and have one problem which leads to my
> recurrent request of goops default behavior should be to [a] always
> create a generic function for accessors and methods that do not [yet]
> have one, visible in the entire guile space [all modules] and [b] the
> default behavior should be '(merge-generics replace warn-override-core
> warn last) [but that at least that one I can set using :duplicate, I
> know]
>
> so, 2 or 3 things to show what happens and see what developers think.
>
>
> 1]
>
> if i use in the repl or in my init.scm
>
> (default-duplicate-binding-handler '(merge-generics replace
> warn-override-core warn last))
>
> ->
>
> david@capac:~/gnu/kise 14 $ guile
> GNU Guile 2.0.7.9-21982
> ...
> scheme@(guile-user)> (default-duplicate-binding-handler
> '(merge-generics replace warn-override-core warn last))
> scheme@(guile-user)> (use-modules (mg-3))
> (mg3/letstry)
>
> ;;; note: source file /usr/alto/projects/gnu/tests/mg-3.scm
> ;;; newer than compiled
> /home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/gnu/te
> sts/mg-3.scm.go ;;; note: auto-compilation is enabled, set
> GUILE_AUTO_COMPILE=0 ;;; or pass the --no-auto-compile argument
> to disable. ;;; compiling /usr/alto/projects/gnu/tests/mg-3.scm
> WARNING: (mg-3): `dialog' imported from both (mg-1) and (mg-2)
> ;;; compiled
> /home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/gnu/te
> sts/mg-3.scm.go WARNING: (mg-3): `dialog' imported from both (mg-1)
> and (mg-2) ERROR: In procedure scm-error:
> ERROR: No applicable method for #<<accessor> dialog (1)> in call
> (dialog #<<widget-a> 1e97660>)
>
>
> 2]
>
> if I uncomment the :duplicates block in mg-3, then it's fine
>
> ... ...
> ;;; ("widget-a:" dialog-a)
>
> ;;; ("widget-b:" dialog-b)
> scheme@(guile-user)>
>
>
> 3]
>
> what is more of a problem with the existing goops default, for me, is
> expressed in the mg-4.scm 'case': i can not make it work unless I
> manually create another module, manually making generics and make sure
> it is loaded before ... or rename the accessors, which both solutions
> are really against my expectation and [long] CLOS practice: why
> should I have to manually do things which are inherent to oop [same
> name for slots pertaining to different classes is so common that i
> can not see any large application not having to do so, for semantic
> reasons].
>
> unless i did miss that there is a way to ask goops to create a generic
> fucntion for accessors and methods per default ?
>
>
> scheme@(guile-user)> (use-modules (mg-4))
> ;;; note: source file /usr/alto/projects/gnu/tests/mg-4.scm
> ;;; newer than compiled
> /home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/gnu/te
> sts/mg-4.scm.go ;;; note: auto-compilation is enabled, set
> GUILE_AUTO_COMPILE=0 ;;; or pass the --no-auto-compile argument
> to disable. ;;; compiling /usr/alto/projects/gnu/tests/mg-4.scm
> ;;; compiled
> /home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/gnu/te
> sts/mg-4.scm.go scheme@(guile-user)> (mg4/letstry)
> ERROR: In procedure scm-error:
> ERROR: No applicable method for #<<accessor> dialog (1)> in call
> (dialog #<<widget-a> 23b7a60>)
>
>
>
> ;; cheers
> cheers :)
> David
>
>
>
> ;;mg-1.scm
>
> (define-module (mg-1)
>
> :use-module (oop goops)
> :
> :export (<widget-a>
>
> dialog
> make-widget-a))
>
> (define-class <widget-a> ()
> (dialog #:accessor dialog #:init-keyword #:dialog #:init-value #f))
>
> (define (make-widget-a)
> (make <widget-a> #:dialog 'dialog-a))
>
>
> ;; mg-2.scm
>
> (define-module (mg-2)
>
> :use-module (oop goops)
> :
> :export (<widget-b>
>
> dialog
> make-widget-b))
>
>
> (define-class <widget-b> ()
> (dialog #:accessor dialog #:init-keyword #:dialog #:init-value #f))
>
> (define (make-widget-b)
> (make <widget-b> #:dialog 'dialog-b))
>
>
> ;; mg3.scm
>
> (define-module (mg-3)
>
> :use-module (oop goops)
> :
> :use-module (mg-1)
> :use-module (mg-2)
>
> #!
>
> :duplicates (merge-generics
>
> replace
> warn-override-core
> warn
> last)
> !#
>
> :export (mg3/letstry))
>
> (define (mg3/letstry)
> (pk "widget-a:" (dialog (make-widget-a)))
> (pk "widget-b:" (dialog (make-widget-b)))
> (values))
>
>
> ;; mg-4.scm
>
> (define-module (mg-4)
>
> :use-module (oop goops)
> :use-module (mg-1)
> :
> :duplicates (merge-generics
>
> replace
> warn-override-core
> warn
> last)
>
> :export (<widget-b>
>
> dialog
> make-widget-b
> mg4/letstry))
>
> (define-class <widget-b> ()
> (dialog #:accessor dialog #:init-keyword #:dialog #:init-value #f))
>
> (define (make-widget-b)
> (make <widget-b> #:dialog 'dialog-b))
>
> (define (mg4/letstry)
> (pk "widget-a:" (dialog (make-widget-a)))
> (pk "widget-b:" (dialog (make-widget-b))))
next prev parent reply other threads:[~2013-02-23 11:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-21 22:51 goops - accessors, methods and generics David Pirotte
2013-02-22 1:16 ` Daniel Hartwig
2013-02-22 23:11 ` David Pirotte
2013-02-23 0:37 ` Daniel Hartwig
2013-03-05 23:30 ` David Pirotte
2013-03-06 0:28 ` Mark H Weaver
2013-03-06 14:15 ` Ludovic Courtès
2013-02-23 11:20 ` Stefan Israelsson Tampe [this message]
2013-02-23 11:44 ` Stefan Israelsson Tampe
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=3870635.z0WUZy3jFd@warperdoze \
--to=stefan.itampe@gmail.com \
--cc=david@altosw.be \
--cc=guile-devel@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).