guile-user
[Top][All Lists]
Advanced

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

Mixing syntax-rule and indentifier-syntax


From: Tobias Brandt
Subject: Mixing syntax-rule and indentifier-syntax
Date: Tue, 17 Jan 2012 00:11:49 +0100

Hi,

is it possible to define a macro that does one thing when
it's in operator position and another when it's not?

I want to define a macro `with-vectors` that transforms this:

(with-vectors (v)
    (v 0)
    (set! (v 0) 'foo)
    (some-procedure v))

into this:

(begin
    (vector-ref v 0)
    (vector-set! v 0 'foo)
    (some-procedure v))

So far I have this:

(define-syntax with-vectors
    (syntax-rules ()
        ((_ (id ...) exp ...)
         (let-syntax ((id* (syntax-rules ()
                               ((_ idx) (vector-ref id idx)))) ...)
             exp ...))))

But that obviously only works for the first case: (v 0).

Regards,
Tobias



reply via email to

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