unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* goops - accessors, methods and generics
@ 2013-02-21 22:51 David Pirotte
  2013-02-22  1:16 ` Daniel Hartwig
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: David Pirotte @ 2013-02-21 22:51 UTC (permalink / raw)
  To: guile-devel

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/tests/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/tests/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/tests/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/tests/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))))



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

end of thread, other threads:[~2013-03-06 14:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-02-23 11:44 ` Stefan Israelsson Tampe

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