From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.user Subject: Re: Modules and GOOPS Date: Thu, 28 Jul 2016 18:14:25 -0300 Message-ID: <20160728181425.5f167237@capac> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/NusK.b8WYajEsVwZzUGX.Ff"; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1469740556 16380 80.91.229.3 (28 Jul 2016 21:15:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Jul 2016 21:15:56 +0000 (UTC) Cc: guile-user@gnu.org To: Kovacsics =?UTF-8?B?UsOzYmVydA==?= Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jul 28 23:15:48 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bSseh-0001OA-Sh for guile-user@m.gmane.org; Thu, 28 Jul 2016 23:15:48 +0200 Original-Received: from localhost ([::1]:55706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSseb-0005Wo-IV for guile-user@m.gmane.org; Thu, 28 Jul 2016 17:15:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSse6-0005UV-CA for guile-user@gnu.org; Thu, 28 Jul 2016 17:15:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSse1-0007eT-5E for guile-user@gnu.org; Thu, 28 Jul 2016 17:15:10 -0400 Original-Received: from maximusconfessor.all2all.org ([79.99.200.102]:57406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSse0-0007Y5-R8 for guile-user@gnu.org; Thu, 28 Jul 2016 17:15:05 -0400 Original-Received: from localhost (unknown [192.168.0.2]) by maximusconfessor.all2all.org (Postfix) with ESMTP id C9AC3A04C145; Thu, 28 Jul 2016 23:14:35 +0200 (CEST) Original-Received: from maximusconfessor.all2all.org ([192.168.0.1]) by localhost (maximusconfessor.all2all.org [192.168.0.2]) (amavisd-new, port 10024) with ESMTP id 2uwfw2dO4fJT; Thu, 28 Jul 2016 23:14:31 +0200 (CEST) Original-Received: from capac (unknown [179.210.35.181]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id 5B068A04C128; Thu, 28 Jul 2016 23:14:30 +0200 (CEST) In-Reply-To: X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 79.99.200.102 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:12803 Archived-At: --Sig_/NusK.b8WYajEsVwZzUGX.Ff Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hello, Before anything else, note that I speak on my own behalf here, not in the n= ame of Guile. I'm saying this because I have an opinionated opinion about Goops, i= ts actual 'design/problems/limitations/bugs' [depending of your point of view], why a= nd 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. 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 syst= em 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 i= t is an error [not implemented by Guile] to redefine a generic function. With the l= ast 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. > ; =3D > (define-module (mbe a) > #:use-module (oop goops) > #:export ( x y)) >=20 > (define-class ()) >=20 > (define-generic x) > (define-generic y) >=20 > (define-method (y (a )) > (display (x a))) >=20 > ; =3D > (define-module (mbe b) > #:use-module (oop goops) > #:use-module (mbe a) > #:export ( x)) It will work if you #:re-export (x): #:export () #:re-export (x)) But that not good enough, imo. We precisely _do not_ want to know if we hav= e 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, obvio= usly! 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 : this will always create a fresh new binding, and so, unlike i= n 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 ()) >=20 > (define-method (x (b )) > 'b) >=20 > ; =3D > (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 =3D (replace warn-override-core warn last) So you'd have=20 #: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/bounc= er.in =09 [ 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. --Sig_/NusK.b8WYajEsVwZzUGX.Ff Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXmnWxAAoJEPN0/ZOjBXrXOC4IAKZ96kuxG/FPxkBGMLol/+xH CDiQJr6M4fiLztN2Vd5HYuvvWX+6ZNptz/YDG/iVtI64jBp8MqynsNdEjqDiHMyn YFiSZ2S5OCjkMphWRxZa+EbQDK6IllcBA+nG7yrbMa2rH34n6lxA3xUlNiDkxHom 1MzkvW/2DQik1i7QHqabNaWWwljDF5vkdcIyXYmISrsdJgkpuTZUu9CCeN3x9N1P WgnX7vcaS9XUeFQ7H/L4/xOSupgSAZ6aVci3uY34A6WMyLJxylSAt0osGhsHc4ar J55o35Wem5b3qrGTUPZyKoMA62ZpKLtdG28Z1ta2/3fHW4+2eFC0NIUbi+fk4tY= =BZg/ -----END PGP SIGNATURE----- --Sig_/NusK.b8WYajEsVwZzUGX.Ff--