From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.user Subject: Re: Problem merging generics across modules Date: Fri, 13 Oct 2017 11:12:42 -0300 Message-ID: <20171013111242.3b23f413@capac> References: <8760bjncez.fsf@ateguix.i-did-not-set--mail-host-address--so-tickle-me> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/bC8/xSyUQgoyMUU0vIon9b4"; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1507904009 1321 195.159.176.226 (13 Oct 2017 14:13:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 13 Oct 2017 14:13:29 +0000 (UTC) Cc: guile-user@gnu.org To: Andrew Erlanger Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Oct 13 16:13:24 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e30iE-0007WV-H7 for guile-user@m.gmane.org; Fri, 13 Oct 2017 16:13:18 +0200 Original-Received: from localhost ([::1]:50508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e30iM-0001W4-1O for guile-user@m.gmane.org; Fri, 13 Oct 2017 10:13:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e30hz-0001Uk-Kh for guile-user@gnu.org; Fri, 13 Oct 2017 10:13:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e30hu-0003Bw-KR for guile-user@gnu.org; Fri, 13 Oct 2017 10:13:03 -0400 Original-Received: from maximusconfessor.all2all.org ([79.99.200.102]:34095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e30hu-00037v-Ay for guile-user@gnu.org; Fri, 13 Oct 2017 10:12:58 -0400 Original-Received: from localhost (unknown [192.168.0.2]) by maximusconfessor.all2all.org (Postfix) with ESMTP id A9338A04C171; Fri, 13 Oct 2017 16:12:56 +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 vTHyK6UKDvOO; Fri, 13 Oct 2017 16:12:50 +0200 (CEST) Original-Received: from capac (unknown [179.210.16.248]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id 7BF03A04C14D; Fri, 13 Oct 2017 16:12:49 +0200 (CEST) In-Reply-To: <8760bjncez.fsf@ateguix.i-did-not-set--mail-host-address--so-tickle-me> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] 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:14208 Archived-At: --Sig_/bC8/xSyUQgoyMUU0vIon9b4 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hello Andrew, > I am trying to extend the definition of a few primitives, > including equal?, in a project of mine. Let's say that a.scm contains: > (define-module (project a) > #:use-module (oop goops) =20 > #:export (equal?) When you extend a guile primitive, don't #:export it in your module definit= ion, because that creates a new binding, hiding guile's core primitive. You shou= ld use #:re-export instead, though in this very specific case of extending a guile= core primitive it is not even necessary, because when guile 'encounter' your define-method, it does this: it creates a generic function for the method name, if it does not already exists, by calling define-generic [1]: define-generic checks that the name was (or not) previously bound to a scheme procedure, in which case it incorporates it into the new generic function as its default procedure it adds your methods to the generic function... David [1] unless you really know what you are doing, you don't want to call define-generic yourself, because if it existed already, then that previous generic function would discarded and replaced by a new, empty generic function. goops calls define-generic for you, as part ofthe define-method protocol, iff there is no generic function for that name, so you are always on the safe side to rely on goops here. ;;; ;;; Extending equal? ;;; (define-module (extending-equal) #:use-module (oop goops) #:export ( !r !g !b)) (define-class () (r #:accessor !r #:init-keyword #:r #:init-value 0) (g #:accessor !g #:init-keyword #:g #:init-value 0) (b #:accessor !b #:init-keyword #:b #:init-value 0)) (define-method (equal? (c1 ) (c2 )) (pk "in extended equal? ...") (and (=3D (!r c1) (!r c2)) (=3D (!g c1) (!g c2)) (=3D (!b c1) (!b c2)))) ;;; ;;; Let's try it ;;; GNU Guile 2.2.2.3-0c102 scheme@(guile-user)> (add-to-load-path (getcwd)) scheme@(guile-user)> ,use (oop goops) scheme@(guile-user)> ,use (extending-equal) ;;; note: source file /usr/alto/projects/guile/goops/extending-equal.scm ;;; ... scheme@(guile-user)> (make ) $2 =3D #< 5610ca6b2ba0> scheme@(guile-user)> (make ) $3 =3D #< 5610ca7480f0> scheme@(guile-user)> (equal? $2 $3) ;;; ("in extended equal? ...") $4 =3D #t --Sig_/bC8/xSyUQgoyMUU0vIon9b4 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEhCJlRZtBM3furJHe83T9k6MFetcFAlngydoACgkQ83T9k6MF etch9Qf/aheTZrWNxc+COu9b9IEZ8tiFKAjLVMicQ3wPDBNOfYHjNucwUtvFWyVf G2PdewKZ6ceXE4B1DPYlwgTNP4z+8maEWynEC7FfQTkYArVeIoVgRQJVLBgusntU EXzGIK6VUlpWzJmpddG2qTryK5rlx+XmGxCa2zrqwMiAJ2QS6cBJfNL6eb7xDLiE oBLU/1COlwqL3/GTyQq4z8qmSz7DUq9Hn01Ao4K2KjIft8Q9d/UwmdtFS2Tj5cPH UI4iU59D477Bv28TfQvHkZs/Vt/zKRz79WuvCZHuYfMTHPztORIEFFplSiTQ8F6C 1+rQSiixKJJ8AV5DmqDHRV8Bldb/9A== =k+7b -----END PGP SIGNATURE----- --Sig_/bC8/xSyUQgoyMUU0vIon9b4--