unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Mixing syntax-rule and indentifier-syntax
@ 2012-01-16 23:11 Tobias Brandt
  2012-01-17  9:22 ` Andy Wingo
  2012-01-17 21:53 ` Ian Price
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Brandt @ 2012-01-16 23:11 UTC (permalink / raw)
  To: guile-user

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-18 16:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-16 23:11 Mixing syntax-rule and indentifier-syntax Tobias Brandt
2012-01-17  9:22 ` Andy Wingo
2012-01-17 21:53 ` Ian Price
2012-01-17 23:26   ` Tobias Brandt
2012-01-18 16:23     ` Andy Wingo

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