[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [GOOPS] Specializing <generic> to allow lazy method addition
From: |
Mikael Djurfeldt |
Subject: |
Re: [GOOPS] Specializing <generic> to allow lazy method addition |
Date: |
Tue, 27 Jan 2004 21:14:57 -0500 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Stephen Compall <address@hidden> writes:
> Mikael Djurfeldt <address@hidden> writes:
>
>> While the MOP for <class> works, the MOP for <generic> isn't yet
>> implemented. This is a shame and I've for very long had had the hope
>> to find time to fix it. What we really quickly should do is to
>> document this situation so that people know that they cannot yet
>> subclass <generic>.
>>
>> The purity flag, which you ask about, marks that a class is
>> "untouched" by the user so that the C runtime can count on specific
>> slots existing and residing at specific locations within an object.
>>
>> The idea is that the runtime will look for specialized functions only
>> if the class isn't pure.
>
> Please tell me if this is accurate: all the Scheme-level procedure
> calls in libguile eventually go through scm_apply in eval.c, which
> contains a switch-on-type for the various kinds of applicable
> objects.
(There is dispatch on type also within the evaluator (scm_ceval).)
> The case that calls `scm_apply_generic', the generic I added a method
> to in trying to make a callable class, first checks for one of the
> flags in the struct, which is why I get "wrong type to apply" anyway.
This is correct.
> I ask this because I am more interested in making objects of any class
> applicable. One case of this is my makefile processor, which
> essentially processes forms, and used to be in closure form (where you
> applied the `object' to each form).
The correct way to make an applicable object is (sorry---couldn't
think of a better example):
(define (incrementor-function o x)
(+ x (increment o)))
(define-class <incrementor> ()
(increment #:init-value 1 #:init-keyword #:increment)
#;metaclass <operator-class>
#:procedure incrementor-function)
(define x (make <incrementor> #:increment 2))
(x 1) --> 3
(set! (increment x) 3)
(x 1) --> 4
Here all objects of class <incrementor> behave the same.
You can also subclass <entity> where every object has individual
behavior.
These also come in variants which have setters, in which case you can
give a meaning to expresions like:
(set! (x ...) ...)
M