From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: GOOPS: Customizing class instantiation Date: Wed, 27 Sep 2006 15:16:28 +0200 Organization: LAAS-CNRS Message-ID: <87irj9witv.fsf@laas.fr> References: <87psdjnig5.fsf@laas.fr> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1159363051 2693 80.91.229.2 (27 Sep 2006 13:17:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 27 Sep 2006 13:17:31 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Sep 27 15:17:29 2006 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GSZHb-0007GI-LQ for guile-user@m.gmane.org; Wed, 27 Sep 2006 15:17:03 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GSZHb-0000a4-2L for guile-user@m.gmane.org; Wed, 27 Sep 2006 09:17:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GSZHV-0000Xh-Ur for guile-user@gnu.org; Wed, 27 Sep 2006 09:16:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GSZHV-0000XL-8z for guile-user@gnu.org; Wed, 27 Sep 2006 09:16:57 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GSZHV-0000XA-5N for guile-user@gnu.org; Wed, 27 Sep 2006 09:16:57 -0400 Original-Received: from [140.93.0.15] (helo=laas.laas.fr) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GSZMM-0003gL-HL for guile-user@gnu.org; Wed, 27 Sep 2006 09:21:58 -0400 Original-Received: by laas.laas.fr (8.13.7/8.13.4) with SMTP id k8RDGoSL020984; Wed, 27 Sep 2006 15:16:52 +0200 (CEST) Original-To: Guile-User X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 6 =?iso-8859-1?Q?Vend=E9miaire?= an 215 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: powerpc-unknown-linux-gnu Mail-Followup-To: Guile-User In-Reply-To: <87psdjnig5.fsf@laas.fr> (Ludovic =?iso-8859-1?Q?Court=E8s's?= message of "Tue, 26 Sep 2006 10:24:58 +0200") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-Spam-Score: 0 () X-Scanned-By: MIMEDefang at CNRS-LAAS X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id k8RDGoSL020984 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:5548 Archived-At: Hi, Nobody won the prize, because nobody gave the correct answer. For those of you who played, I'm giving the correct answer below. ;-) ludovic.courtes@laas.fr (Ludovic Court=E8s) writes: > (use-modules (oop goops)) > (read-set! keywords 'prefix) > > (define-class () > (the-slot :init-value #t)) > > > (define-method (compute-cpl (c )) > (format (current-error-port) "CPL (~a)~%" c) > (list c )) > > (define-method (make-instance (c )) > (format (current-error-port) "make-instance (~a)~%" c) > (next-method)) > > > (define (make-a-class name) > (let ((c (make ))) > (slot-set! c 'name name) > c)) > > The issue is that when instantiating an instance of `' (read > that twice ;-)), I'm getting the following error: > > ;; Create a class (instance of `'). > guile> (define c (make-a-class 'paf)) > CPL (#< ??? 301f8930>) > guile> c > #< paf 301f8930> > > ;; Instantiate it. > guile> (make c) > make-instance (#< paf 301f8930>) > > : In expression (let* (#) (format # "make-instance (~a)= ~%" ...) ...): > : No applicable method for #< initialize (10)>= in call (initialize # ()) > ABORT: (goops-error) The whole issue here is that `%allocate-instance' (aka. `scm_sys_allocate_instance') returns an apparently improperly initialized object (a raw struct) instead of a regular GOOPS object that has a class, etc. Since there are no `initialize' methods for raw structs, we get this no-applicable-method error. But why is it so? Looking at `goops.c', it's actually `wrap_init ()' that returns the offending struct. However, `wrap_init ()' _does_ specify class information as part of the type tag. So perhaps it is the class information that is not properly initialized in the case of an instance of `'? The correct way to instantiate a class is found in `make-class' in `goops.scm'. This function passes several keyword arguments to `make' that my `make-a-class' function did not provide. In particular, the `:dsupers' argument is the one that must not be forgotten: guile> (make (make )) [...] : No applicable method for #< initialize (11)> i= n call (initialize # ()) guile> (make (make :dsupers (list ))) # Note that the `compute-cpl' method specialized for `' is still needed and it must contain a class for which an `initialize' method exists (i.e., not `'): (define-method (compute-cpl (c )) (list c )) Notice: `compute-cpl' and `:dsupers' don't even have to agree... Now, this does not really explain why an instance of such an improperly-initialized class would show up as a raw struct. Well, clarifying is left as an exercise to the reader. :-) In short, the lesson is: one should use `make-class' (although it's undocumented) rather than `(make ...)' when instantiating a new class. Thanks, Ludovic. _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user