This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: goops: how to make callable objects?
- To: Marius Vollmer <mvo at zagadka dot ping dot de>
- Subject: Re: goops: how to make callable objects?
- From: Mikael Djurfeldt <mdj at mdj dot nada dot kth dot se>
- Date: 04 Nov 1999 10:45:38 +0100
- Cc: guile at sourceware dot cygnus dot com
- Cc: djurfeldt at nada dot kth dot se
- References: <87vh7jnrw0.fsf@zagadka.ping.de>
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)
?
> 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. E.g., in the tutorial, I
think there's an example where the internal representation of a
complex number is chosen as cartesian but where you can give values in
polar format by using #:magnitude and #:angle.
> How can I define a default value for it?)
Is this a common need? 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.
However, we *could* make procedure appear as an ordinary slot. But we
should probably not have a setter for it in order to support efficient
application and compilation. (The bound object-procedure will be
fixed so that we always can rely on having the same semantics when
applying the object.)
The choice of not having a normal procedure slot has to do with the
fact that some objects can be both an entity and an operator-class and
that we need to be able to rely on that the corresponding slots have a
fixed position within the object.
If we would make the procedure slot appear normal, the procedure would
still be stored at its current special location.