[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Smobs and setters?
From: |
Daniel Skarda |
Subject: |
Re: Smobs and setters? |
Date: |
25 May 2001 13:46:54 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
Hello,
it is quite strange to reply to my own mail :) I was playing with guile
source, I extended smob with scm_set_smob_setter and scm_setter function with
ability to return smob's setter. Than I hit the wall :)
Setters for smobs are different from procedure setters - they require one more
argument - smob itself (it is more like method than procedure). Current
generalized `set!' macro does:
(set! var val)
-=> (real-set! var val)
(set! (proc arg1 ..) val)
-=> ((setter proc) arg1 ... val)
I can think about two ways how to simply add smob setters to guile - rewrite
generalised set! macro to return
(set! (dest arg1 .. argn) val)
-=> (if (smob? val)
((setter dest) dest arg1 .. argn val)
((setter dest) arg1 ... argn val))
or
-=> (setter-aply dest arg1 ... argn val)
where setter-apply implements on C level what was done in previous example in
scheme level (if ...). I do not like the first way because it does not look
elegant (but `if' is imho necessary) and I do not know if setter-apply can by
created by scm_c_define_subr (I browsed through eval.c looking for
implementation
of apply and I was quite mixed up - but maybe further study of guile sources
clears it :)
As I am writing this mail I realized that I have not looked into GOOPS and
(as scm_setter function suggests) into structs/objects. How these areas of guile
would affect final solution?
Best regards,
Dan Skarda
> Hello,
>
> in my application I took an advantage of scm_set_smob_apply. Imagine we
> create
> vec3d
>
> vec3d_tag = scm_make_smob_type ("vec3d", 3 * sizeof (double));
>
> I know that the usual Scheme way is to define two function - `vec-ref' and
> `vec-set!' for accessing values stored in vec3d. Using setter/getter we would
> like to write:
>
> (define v (make-vec 0 1 2))
>
> (v 1)
> -=> 1
>
> (set! (v 2) 4)
> v
> -=> #<vec3d 0 1 4>
>
> It is possible to implement getter (v 1) using scm_set_smob_apply. However
> it
> is not possible to write setter function. It is possible to make procedure
> with
> setter, but it is not possible to attach setter to smobs :-(
>
> I am sorry that my mail ends with "request for feature" instead of patch -
> but
> my knowledge of guile internals is not that deep :(
>
> Best regards,
> Dan Skarda
>
>
>
> _______________________________________________
> Guile-devel mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/guile-devel