From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pat Lasswell" Newsgroups: gmane.lisp.guile.user Subject: Re: GOOPS: Customizing class instantiation Date: Tue, 26 Sep 2006 08:26:22 -0700 Message-ID: References: <87psdjnig5.fsf@laas.fr> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0120990526==" X-Trace: sea.gmane.org 1159284650 11562 80.91.229.2 (26 Sep 2006 15:30:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 26 Sep 2006 15:30:50 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Sep 26 17:30:49 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 1GSEpK-0003tY-Lp for guile-user@m.gmane.org; Tue, 26 Sep 2006 17:26:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GSEpK-0003dL-2A for guile-user@m.gmane.org; Tue, 26 Sep 2006 11:26:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GSEpE-0003d3-M5 for guile-user@gnu.org; Tue, 26 Sep 2006 11:26:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GSEpE-0003cl-1e for guile-user@gnu.org; Tue, 26 Sep 2006 11:26:24 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GSEpD-0003cb-S1 for guile-user@gnu.org; Tue, 26 Sep 2006 11:26:23 -0400 Original-Received: from [64.233.166.177] (helo=py-out-1112.google.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GSEts-0002e4-Mz for guile-user@gnu.org; Tue, 26 Sep 2006 11:31:12 -0400 Original-Received: by py-out-1112.google.com with SMTP id d42so744139pyd for ; Tue, 26 Sep 2006 08:26:22 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=p+JyJh+an7seWepPihCRcuPb+SOO0wiMzzqXK+XYJv26GsRUPvUUtfnD4WvjoL0gWxLmCwicOKKgCLiZZb0cnNxW/qF0RpuD0l88VWcrU0jUhVnD6hKX2MA19mhMTGzgV8ehnKbjlG0OWo4YRCfQ5GGnFxRwkdwqITrQhrOtxTc= Original-Received: by 10.35.117.5 with SMTP id u5mr1026025pym; Tue, 26 Sep 2006 08:26:22 -0700 (PDT) Original-Received: by 10.35.74.15 with HTTP; Tue, 26 Sep 2006 08:26:22 -0700 (PDT) Original-To: Guile-User In-Reply-To: <87psdjnig5.fsf@laas.fr> 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:5545 Archived-At: --===============0120990526== Content-Type: multipart/alternative; boundary="----=_Part_10428_33384125.1159284382282" ------=_Part_10428_33384125.1159284382282 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/26/06, Ludovic Court=E8s wrote: (define-method (make-instance (c )) (format (current-error-port) "make-instance (~a)~%" c) (next-method)) Try adding a '. initargs' after '(c )'. cheers pat On 9/26/06, Ludovic Court=E8s wrote: > > Hi, > > I'm trying to "dynamically" create classes which I would then like to > instantiate. The behavior I would like to achieve is that: > > guile> (define c (make-a-class 'some-name)) > guile> (define obj (make c)) > guile> obj > #< some-name deadbeef> > > To that purpose, I have a metaclass named `' and a procedure > `make-a-class' that simply returns instances of `'. Since > `compute-cpl' is customized for instances of `', I can make > sure that instances of `' have a proper CPL that includes > `'. Here's the code: > > (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)> i= n > call (initialize # ()) > ABORT: (goops-error) > > This is quite unexpected since I would expect, at least, the > `initialize' class for instances of `' to be applicable. The other > surprising thing is that the instance to be initialized is still seen as > # instead of # or some such. > > Any idea? > > Thanks, > Ludovic. > > > _______________________________________________ > Guile-user mailing list > Guile-user@gnu.org > http://lists.gnu.org/mailman/listinfo/guile-user > ------=_Part_10428_33384125.1159284382282 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 9/26/06, Ludov= ic Court=E8s <ludovic.cou= rtes@laas.fr> wrote:

  (define-method (make-insta= nce (c <my-class>))
    (format (current-error-port) "make-instanc= e (~a)~%" c)
    (next-method))

Try addi= ng a '. initargs' after '(c <my-class>)'.

cheers
pat
On 9/26/06,=20 Ludovic Court=E8s <ludovic.courtes@laas.fr> wrote: Hi,

I'm trying to "dynamically" create classes which I wou= ld then like to
instantiate.  The behavior I would like to ach= ieve is that:

  guile> (define c (make-a-class 'some-na= me))
  guile> (define obj (make c))
  guile> obj
  #<<my-class> some-nam= e deadbeef>

To that purpose, I have a metaclass named `<my-cla= ss>' and a procedure
`make-a-class' that simply returns instances of = `<my-class>'.  Since
`compute-cpl' is customized for instances of `<my-class>', I can = make
sure that instances of `<my-class>' have a proper CPL that in= cludes
`<top>'.  Here's the code:

  (us= e-modules (oop goops))
  (read-set! keywords 'prefix)

  (define-cla= ss <my-class> (<class>)
    (the-slot :i= nit-value #t))


  (define-method (compute-cpl (c <my= -class>))
    (format (current-error-port) "= CPL (~a)~%" c)
    (list c <top>))

  (defin= e-method (make-instance (c <my-class>))
    (f= ormat (current-error-port) "make-instance (~a)~%" c)
 &nb= sp;  (next-method))


  (define (make-a-class = name)
    (let ((c (make <my-class>)))
 &nb= sp;    (slot-set! c 'name name)
   &n= bsp;  c))

The issue is that when instantiating an instance= of `<my-class>' (read
that twice ;-)), I'm getting the following = error:

  ;; Create a class (instance of `<my-class>').
=   guile> (define c (make-a-class 'paf))
  CPL (#&= lt;<my-class> ??? 301f8930>)
  guile> c
 &= nbsp;#<<my-class> paf 301f8930>

  ;; Instantiate it.
  guile> (make c)
&nb= sp; make-instance (#<<my-class> paf 301f8930>)

&nbs= p; <unnamed port>: In expression (let* (#) (format # "make-= instance (~a)~%" ...) ...):
  <unnamed port>: No applicable method for #<<generic= > initialize (10)> in call (initialize #<struct 301f8930:301f7320&= gt; ())
  ABORT: (goops-error)

This is quite unexpected= since I would expect, at least, the
`initialize' class for instances of `<top>' to be applicable.&nbs= p; The other
surprising thing is that the instance to be initialize= d is still seen as
#<struct ...> instead of #<paf ...> or so= me such.

Any idea?

Thanks,
Ludovic.


___________________= ____________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
=
------=_Part_10428_33384125.1159284382282-- --===============0120990526== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user --===============0120990526==--