The general question is "when should I prefer functions versus macros?" but a specific example would be this:
I'm doing some database programming and I wanted a thing that would handle transactions for me. Doing it as a function would look something like this: (define (in-transaction dbh body) (define success #f) (dynamic-wind (thunk (query-exec dbh "BEGIN TRANSACTION")) (thunk (let ((result (body))) (set! success #t) ;; we didn't throw, so we succeeded result)) (thunk (query-exec dbh (if success "END TRANSACTION" "ROLLBACK"))))) And then I could call it like so: (in-transaction (thunk (query-exec dbh "...sql goes here..."))) Doing it as a macro would eliminate the need for the 'thunk' when calling it, but writing macros is a bit more complicated than writing functions and arguably harder for debugging. How would you all handle this if you were writing it? Secondarily, is there a better way to pass success/fail state between the body and the post thunk in a dynamic-wind? -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.