unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* base class parameterisation?
@ 2007-06-09  6:18 Marco Maggi
  2007-06-12 20:50 ` Andy Wingo
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Maggi @ 2007-06-09  6:18 UTC (permalink / raw)
  To: guile-user

Ciao,

  I am using GOOPS and I have a hierarchy like this:

        ---A---
       |       |
       v       v
       A1      A2

           B

I wonder if there is a way to parameterise the construction
of 'B' to let it have 'A1' or 'A2' as base class. I do not
want to use delegation.

TIA

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"



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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: base class parameterisation?
  2007-06-09  6:18 Marco Maggi
@ 2007-06-12 20:50 ` Andy Wingo
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2007-06-12 20:50 UTC (permalink / raw)
  To: guile-user

Hi Marco,

On Sat, 2007-06-09 at 08:18 +0200, Marco Maggi wrote:
>         ---A---
>        |       |
>        v       v
>        A1      A2
> 
>            B
> 
> I wonder if there is a way to parameterise the construction
> of 'B' to let it have 'A1' or 'A2' as base class. I do not
> want to use delegation.

I suspect you will have to make a metaclass and specialize on
allocate-instance. Something like (my GOOPS is rusty):

(define-class A-metaclass (<class>))

(define-method (allocate-instance (class A-metaclass) initargs)
  (if (random-predicate) (allocate-instance A1) (allocate-instance A2)))

(define-class B () #:metaclass A-metaclass ..)

Good luck,

Andy.
-- 
http://wingolog.org/


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: base class parameterisation?
@ 2007-06-25 13:57 Marco Maggi
  0 siblings, 0 replies; 3+ messages in thread
From: Marco Maggi @ 2007-06-25 13:57 UTC (permalink / raw)
  To: guile-user

On Tue Jun 12 22:50:02 2007 +0200 "Andy Wingo" wrote:
>On Sat, 2007-06-09 at 08:18 +0200, Marco Maggi wrote:
>>         ---A---
>>        |       |
>>        v       v
>>        A1      A2
>>
>>            B
>>
>>I wonder if there is a way to parameterise the
>>construction of 'B' to let it have 'A1' or 'A2'
>>as base class. I do not want to use delegation.
>
>I suspect you will have to make a metaclass and
>specialize on allocate-instance. Something like
>(my GOOPS is rusty):
>
>(define-class A-metaclass (<class>))
>
>(define-method (allocate-instance (class A-metaclass)
>                                  initargs)
>  (if (random-predicate) (allocate-instance A1)
>      (allocate-instance A2)))
>
>(define-class B () #:metaclass A-metaclass ..)

Mh, no[1]. But thanks anyway, it has been a good
occasion to inspect some of GOOPS.

Meanwhile I have changed my design, so I need that
no more.

Ciao.

[1] <http://community.schemewiki.org/?goops-allocate-instance>

--
Marco Maggi




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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-25 13:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-25 13:57 base class parameterisation? Marco Maggi
  -- strict thread matches above, loose matches on Subject: below --
2007-06-09  6:18 Marco Maggi
2007-06-12 20:50 ` Andy Wingo

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).