unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Pat Lasswell" <imofftoseethewizard@gmail.com>
Subject: Re: GOOPS: Customizing class instantiation
Date: Tue, 26 Sep 2006 08:26:22 -0700	[thread overview]
Message-ID: <ca8589e00609260826y70d2876boffc7a50fb4fd2f50@mail.gmail.com> (raw)
In-Reply-To: <87psdjnig5.fsf@laas.fr>


[-- Attachment #1.1: Type: text/plain, Size: 2605 bytes --]

On 9/26/06, Ludovic Courtès <ludovic.courtes@laas.fr> wrote:

  (define-method (make-instance (c <my-class>))
    (format (current-error-port) "make-instance (~a)~%" c)
    (next-method))

Try adding a '. initargs' after '(c <my-class>)'.

cheers
pat

On 9/26/06, Ludovic Courtès <ludovic.courtes@laas.fr> 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
>   #<<my-class> some-name deadbeef>
>
> To that purpose, I have a metaclass named `<my-class>' 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 includes
> `<top>'.  Here's the code:
>
>   (use-modules (oop goops))
>   (read-set! keywords 'prefix)
>
>   (define-class <my-class> (<class>)
>     (the-slot :init-value #t))
>
>
>   (define-method (compute-cpl (c <my-class>))
>     (format (current-error-port) "CPL (~a)~%" c)
>     (list c <top>))
>
>   (define-method (make-instance (c <my-class>))
>     (format (current-error-port) "make-instance (~a)~%" c)
>     (next-method))
>
>
>   (define (make-a-class name)
>     (let ((c (make <my-class>)))
>       (slot-set! c 'name name)
>       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 (#<<my-class> ??? 301f8930>)
>   guile> c
>   #<<my-class> paf 301f8930>
>
>   ;; Instantiate it.
>   guile> (make c)
>   make-instance (#<<my-class> paf 301f8930>)
>
>   <unnamed port>: In expression (let* (#) (format # "make-instance (~a)~%"
> ...) ...):
>   <unnamed port>: No applicable method for #<<generic> initialize (10)> in
> call (initialize #<struct 301f8930:301f7320> ())
>   ABORT: (goops-error)
>
> This is quite unexpected since I would expect, at least, the
> `initialize' class for instances of `<top>' to be applicable.  The other
> surprising thing is that the instance to be initialized is still seen as
> #<struct ...> instead of #<paf ...> or some such.
>
> Any idea?
>
> Thanks,
> Ludovic.
>
>
> _______________________________________________
> Guile-user mailing list
> Guile-user@gnu.org
> http://lists.gnu.org/mailman/listinfo/guile-user
>

[-- Attachment #1.2: Type: text/html, Size: 3883 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

  parent reply	other threads:[~2006-09-26 15:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-26  8:24 GOOPS: Customizing class instantiation Ludovic Courtès
2006-09-26 11:47 ` Ludovic Courtès
2006-09-26 15:26 ` Pat Lasswell [this message]
2006-09-27  8:20   ` Ludovic Courtès
2006-09-27 13:16 ` Ludovic Courtès
2006-09-28  8:50   ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ca8589e00609260826y70d2876boffc7a50fb4fd2f50@mail.gmail.com \
    --to=imofftoseethewizard@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).