This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: goops: how to make callable objects?


Mikael Djurfeldt <mdj@mdj.nada.kth.se> writes:

> Marius Vollmer <mvo@zagadka.ping.de> writes:
> 
> > I don't know what <magic-base-class> and magic-apply should be in
> > reality.  I know about <entity> and <operator> but I couldn't figure
> > out how to use them. (That is I got as far as
> > 
> >     (define e (make <entity> :procedure pk))
> >     (e 1 2 3)
> >     ;;; (#<<entity> 40255d98> 1 2 3)
> 
> What about:
> 
> (define-class <foo> ()
>   #:metaclass <operator-class>
>   #:procedure (lambda args (write-line (cons 'a-foo-has-been-called args))))
> 
> (define f (make <foo>))
> 
> (f 1 2 3)
> ;;; (a-foo-has-been-called #<<foo> 4054b6c0> 1 2 3)
> 
> ?

Exactly right, thanks!  I'm perfectly happy with that.

> > but I'm unhappy about the explicit `:procedure' argument to `make'.
> > `:procedure' does not seem to correspond to a regular slot.
> 
> You should not think of keyword arguments as always corresponding to
> slots.  They can signify anything really.

Yes, I didn't want to apply that something is wrong with <entity> or
with the :procedure argument.  It's just that (as you said) I really
want to associate the procedure with the class, not with the object.

> > How can I define a default value for it?)
> 
> Is this a common need?

No, I don't think so.

> It seems to me that what you're really looking for is to associate
> the procedure with the class instead of the instance.  Then you use
> <operator-class> as above.

Yes, exactly.  Thanks for clarifying that.
 
> However, we *could* make procedure appear as an ordinary slot.

I don't think I know enough about the internals of GOOPS to argue
about this.  It's still mysterious to me how <generic> gets its act
together. ;)

- Marius

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]