[racket] macro for broken abstraction?

From: Alexander D. Knauth (alexander at knauth.org)
Date: Mon Dec 8 21:12:23 EST 2014

Sorry I missed this:

On Dec 8, 2014, at 6:45 PM, George Neuner <gneuner2 at comcast.net> wrote:

> and code in the  <body> needs to reference “db"

(define (boiler-plate/f f)
  (define err-msg #f)
  (let/ec fail-network
    (with-handlers ([exn:fail:network?
                     (lambda (e)
                       (set! err-msg "database connection error")
                       (fail-network err-msg))])
      (let ([db (connect-database)])
        (define (thunk)
          (f db))
        (let/ec fail-sql
          (with-handlers ([exn:fail:sql?
                           (lambda (e)
                             (let ([info (exn:fail:sql-info e)])
                               (set! err-msg (cdr (assoc 'message info)))
                               (fail-sql err-msg)))])
            (call-with-transaction db thunk #:isolation 'repeatable-read))
          (disconnect db)
          err-msg)))))

(define-syntax-rule (boiler-plate db body ...)
  (boiler-plate/f (λ (db) body ...)))

(let ()
  (define err-msg
    (boiler-plate
     db
     < body ... >
     ))
  ; err-msg needed here
  err-msg
  )

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141208/957a9c81/attachment.html>

Posted on the users mailing list.