[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: accessor with 2/3 parameters

From: Neil Jerram
Subject: Re: accessor with 2/3 parameters
Date: Sat, 19 Aug 2006 11:29:19 +0100
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

"Marco Maggi" <address@hidden> 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]