[plt-scheme] one macro in another?

From: Jos Koot (jos.koot at telefonica.net)
Date: Mon Aug 11 06:16:03 EDT 2008

In this case you should not use syntax-unquote, but you must introduce 
identifier "finally" by means of datum->syntax (or datum->syntax-object) in 
order to make it visible within the form that calls transaction.
Jos

----- Original Message ----- 
From: "Jay F Kominek" <jkominek at miranda.org>
To: <plt-scheme at list.cs.brown.edu>
Sent: Sunday, August 10, 2008 11:54 PM
Subject: [plt-scheme] one macro in another?


> 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)
>               (final-proc)
>               v)))])))
>
> 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
>  (transaction
>    (set-account-balance (+ 10 (read-account-balance)))
>    (finally (printf "account balance updated~n")))
> or even
>  (transaction
>    (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>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme 



Posted on the users mailing list.