[plt-scheme] one macro in another?

From: Jay F Kominek (jkominek at miranda.org)
Date: Sun Aug 10 17:54:23 EDT 2008

This is roughly what I'm trying to accomplish:

(define-syntax transaction
  (lambda (stx)
    (syntax-case stx ()
      [(_ expr ...)
       #`(let ([final-proc #f])
           #,(define-syntax finally
               (lambda (stx)
                 (syntax-case stx ()
                   [(_ exp (... ...))
                    (syntax (set! final-proc (lambda () exp (... ...))))])))
           (let ([v (begin
                      expr ...)])
             (when (procedure? final-proc)

But you can't stick define-syntax in let.

A pointer in the right direction would be appreciated. I have a
feeling I need some kind of with-syntax or let-syntax thingy, but
I havn't had the first bit of luck figuring that out.

The goal, for what it is worth, is to be able to write something like
    (set-account-balance (+ 10 (read-account-balance)))
    (finally (printf "account balance updated~n")))
or even
    (let ([new-balance (+ 10 (read-account-balance))])
      (set-account-balance new-balance)
      (finally (printf "new balance is: ~a~n" new-balance))))
and have some behind-the-scenes logic rerun the transaction body as
necessary to deal with serialization or deadlock errors, and then at
the very end just run the finally block.

Jay Kominek <jkominek at miranda.org>

Posted on the users mailing list.