"Marco Maggi" <[EMAIL PROTECTED]> writes:

> So a working example is:
>
> ;; ----------------------------------------
>
> (use-modules (oop goops))
>
> (debug-enable 'debug)
> (debug-enable 'backtrace)
> (debug-enable 'trace)
>
>
> (define-class <my-vec> ()
>   (v #:init-keyword #:value))
>
> (define elm (ensure-accessor
>            (make-procedure-with-setter
>             (lambda (v k)
>               (vector-ref (slot-ref v 'v) k))
>             (lambda (v k value)
>               (vector-set! (slot-ref v 'v) k value)))))
>
> (define-method (display (o <my-vec>) (port <port>))
>   (display (slot-ref o 'v) port))
>
> (define v (make <my-vec> #:value #(1 2 3)))
>
> (set! (elm v 1) -9)
> (display v)(newline)
> (display (elm v 0))(newline)
> (display (elm v 1))(newline)
> (display (elm v 2))(newline)

Do you need the `ensure-accessor' wrapper in order for this example to
work?  I suspect not.

In other words, I think you should get the same result with

 (define elm (make-procedure-with-setter
              (lambda (v k)
                (vector-ref (slot-ref v 'v) k))
              (lambda (v k value)
                (vector-set! (slot-ref v 'v) k value))))

>   I do not like it because ELM does not know about
> <my-vec>, but at  least ELM is a  generic function.

But you don't actually use the generic-ness here, do you?

> Is there a better way to do it?

Not that I know of.  I'll take a look at the code though.

Regards,
     Neil



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

Reply via email to