From: "Marco Maggi" <marco.maggi-ipsu@poste.it>
Subject: accessor with 2/3 parameters
Date: Fri, 18 Aug 2006 20:35:45 +0200 [thread overview]
Message-ID: <J47IBL$F64BF00D3C0BE50899FD3E50DFE1CD22@poste.it> (raw)
Ciao,
I wanted to create an accessor called ELM with synopsis:
(set! (elm obj key) value)
(elm obj key)
which is the same required by the VECTOR-SET! and
VECTOR-REF pair. For this both the #:accessor
keyword of class definition and the explicit
definition:
(define-method (elm (obj <my-class>) key) ...)
(define-method ((setter elm) (obj <my-class>) ...) ...)
do not work. I had to use:
(export elm)
(set! elm (ensure-accessor
(make-procedure-with-setter
(lambda (o key)
...)
(lambda (o key value)
...))))
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)
;; ----------------------------------------
I do not like it because ELM does not know about
<my-vec>, but at least ELM is a generic function.
Is there a better way to do it?
If there is a solution it could be a good idea to
add the implementation example to the GOOPS
documentation.
--
Marco Maggi
"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next reply other threads:[~2006-08-18 18:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-18 18:35 Marco Maggi [this message]
2006-08-19 10:29 ` accessor with 2/3 parameters Neil Jerram
2006-08-19 23:17 ` Neil Jerram
-- strict thread matches above, loose matches on Subject: below --
2006-08-20 6:08 Marco Maggi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='J47IBL$F64BF00D3C0BE50899FD3E50DFE1CD22@poste.it' \
--to=marco.maggi-ipsu@poste.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).