This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
C like syntax
Marius Vollmer <mvo@zagadka.ping.de> writes:
> I don't like that a simple C statement like
>
> obj->x++;
>
> turns into
>
> (set! (gto-canvas-x obj) (1+ (gto-canvas-x obj)))
>
> with my style of choosing accessor names, but I hope to write this
> like
>
> (with-struct-accessors ((gto-canvas x obj))
> (set! x (1+ x)))
>
> in the future. If you regard the `with-struct-accesors' line as
> analogous to a (unavoidable) type declaration of obj in C, this is not
> at all bad.
>
> So to summarize: I don't think we should change the syntax of Guile to
> make accessors different from other functions. However, there should
> be enough hooks into the reader to let people bend the syntax quite
> badly if they want to.
Is it possible to use C like syntax like this by using a transformer
or something?
(let ((i #f) (v (make-vector 5)))
{
for (i = 0; i < 5; i++)
v[i] = obj->x;
})
turns into
(let ((i #f) (v (make-vector 5)))
(set! i 0)
(while (< i 5)
(vector-set! v i (x obj))
(set! i (+ i 1))))
If this can be done, it may be useful when one want to write many
mathematical expressions.
-- Kei