[Top][All Lists]

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

Re: accessor with 2/3 parameters

From: Marco Maggi
Subject: Re: accessor with 2/3 parameters
Date: Sun, 20 Aug 2006 08:08:02 +0200

"Neil Jerram" wrote:
>Well, the following seems to work ...
>In other words, it appears that the args of
>can be generics.

Yes! The following appears to do what I want:

(use-modules (oop goops))

(define-class <my-vec> ()
  (v #:init-keyword #:value))

(define-method (my-vec-setter (v <my-vec>) k)
  (vector-ref (slot-ref v 'v) k))

(define-method (my-vec-getter (v <my-vec>) k value)
  (vector-set! (slot-ref v 'v) k value))

(define elm (make-procedure-with-setter
              my-vec-setter my-vec-getter))

(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)

Thank You!

My real code does not act upon Guile vectors but upon
a custom class that wraps a custom SMOB. I require the
generic-ness of ELM to let other Guile extensions take
it in an attempt to write math functions 'compatible'
with Guile-GSL.

Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"

reply via email to

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