[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lazy evaluation: Goops class/instance customization
From: |
Maarten Grachten |
Subject: |
lazy evaluation: Goops class/instance customization |
Date: |
Mon, 19 May 2003 13:09:50 +0200 (CEST) |
Hi,
I'm trying to create a system for lazy evaluation. That is, I would like
to have a class whose slot-values are evaluated when they are accessed
(and not when the slot-values are set for the objects of that class).
I thought a way to do this would be by creating a macro
'make-lazy' that wraps a 'delay' around the initial slot-values and
customizing the class creation to put a 'force' in the
getter.
Thus, I came up with the following code:
(define-class <Lazy-Eval-Metaclass> (<class>))
(define (make-lazy-closure-variable class)
(let ((shared-variable (make-unbound)))
(list (lambda (o) (primitive-eval (force shared-variable)))
(lambda (o v) (set! shared-variable v)))))
(define-method (compute-get-n-set (c <Lazy-Eval-Metaclass>) slot-defs)
(make-lazy-closure-variable c))
(defmacro make-lazy (specification . body)
(let ((attributes (map (lambda (x)
(if (keyword? x) x (delay x)))
body)))
`(make ,specification
,@attributes)))
(define-class <lazy-class> ()
(s1 #:init-keyword #:s1 #:accessor s1)
#:metaclass <Lazy-Eval-Metaclass>)
And this works basically: when I do
(define obj (make-lazy <lazy-class> #:s1 x))
and
(define x 1)
then
(s1 obj)
returns 1.
But (perhaps not surprisingly) this approach only creates only one
slot-variable for all instances. Like the slots were all class-slots
instead of instance-slots. And I want instance slots.
Well now, in the Goops manual there is a rather abstract part about
customizing instance creation but it doesn't help me. I don't know how
to specialize the initialize method for objects, since I don't know
what basic stuff to put in the initialize methods, besides my
customized stuff. A look in goops.scm reveals:
(define-method (initialize (object <object>) initargs)
(%initialize-object object initargs))
This % stuff leaves me at a blank. So my question is either:
Can anybody tell me if there is any way to investigate the code that
was substituted by %initialize-object?
or
Does anybody see how my code above can be easily changed so as to
admit the lazy evaluation?
Thanks very much,
Maarten Grachten
- lazy evaluation: Goops class/instance customization,
Maarten Grachten <=
- Re: lazy evaluation: Goops class/instance customization, Mikael Djurfeldt, 2003/05/20
- Re: lazy evaluation: Goops class/instance customization, Maarten Grachten, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, Mikael Djurfeldt, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, Maarten Grachten, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, Mikael Djurfeldt, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, Maarten Grachten, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, David Allouche, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, Mikael Djurfeldt, 2003/05/21
- Re: lazy evaluation: Goops class/instance customization, Maarten Grachten, 2003/05/22