<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hi Alexander,<br>
<br>
Your solution is a little more in the functional style than what I
did (below). Compared to mine it changes the semantics from a
stand-alone statement to an expression returning a value, but that
really is not a significant difference. I do like that it
encapsulates the definition of the error return variable.<br>
<br>
Thanks,<br>
George<br>
<br>
<tt><br>
</tt><tt>(define-syntax with-database-connection</tt><tt><br>
</tt><tt> (syntax-rules ()</tt><tt><br>
</tt><tt> ((with-database-connection conn err body ...)</tt><tt><br>
</tt><tt> ; -- start template</tt><tt><br>
</tt><tt> (let/ec fail-network</tt><tt><br>
</tt><tt> (with-handlers [</tt><tt><br>
</tt><tt> (exn:fail:network?</tt><tt><br>
</tt><tt> (lambda (e)</tt><tt><br>
</tt><tt> (set! err "database connection
error")</tt><tt><br>
</tt><tt> (fail-network)))</tt><tt><br>
</tt><tt> ]</tt><tt><br>
</tt><tt> (let [</tt><tt><br>
</tt><tt> (conn (connect-database))</tt><tt><br>
</tt><tt> (sql-cmd #f)</tt><tt><br>
</tt><tt> ]</tt><tt><br>
</tt><tt> (let/ec fail-sql</tt><tt><br>
</tt><tt> (with-handlers [</tt><tt><br>
</tt><tt> (exn:fail:sql? </tt><tt><br>
</tt><tt> (lambda (e)</tt><tt><br>
</tt><tt> (let [(info
(exn:fail:sql-info e))]</tt><tt><br>
</tt><tt> (set! err (cdr (assoc
'message info)))</tt><tt><br>
</tt><tt> (fail-sql))))</tt><tt><br>
</tt><tt> ]</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> (call-with-transaction conn</tt><tt><br>
</tt><tt> (lambda ()</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> body ... </tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> )</tt><tt><br>
</tt><tt> #:isolation 'repeatable-read)</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> )</tt><tt><br>
</tt><tt> (disconnect conn))</tt><tt><br>
</tt><tt> )))</tt><tt><br>
</tt><tt> ; -- end template</tt><tt><br>
</tt><tt> )))</tt><tt><br>
</tt><br>
<br>
<br>
<br>
<br>
On 12/8/2014 9:12 PM, Alexander D. Knauth wrote:<br>
</div>
<blockquote
cite="mid:81F91D5E-3A2F-4ADE-BA13-3723C09F7185@knauth.org"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div>Sorry I missed this:</div>
<br>
<div>
<div>On Dec 8, 2014, at 6:45 PM, George Neuner <<a
moz-do-not-send="true" href="mailto:gneuner2@comcast.net">gneuner2@comcast.net</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">and code in the <body> needs to
reference “db"</blockquote>
<br>
</div>
<div>
<div><font face="Courier New">(define (boiler-plate/f f)</font></div>
<div><font face="Courier New"> (define err-msg #f)</font></div>
<div><font face="Courier New"> (let/ec fail-network</font></div>
<div><font face="Courier New"> (with-handlers
([exn:fail:network?</font></div>
<div><font face="Courier New"> (lambda (e)</font></div>
<div><font face="Courier New"> (set!
err-msg "database connection error")</font></div>
<div><font face="Courier New">
(fail-network err-msg))])</font></div>
<div><font face="Courier New"> (let ([db
(connect-database)])</font></div>
<div><font face="Courier New"> (define (thunk)</font></div>
<div><font face="Courier New"> (f db))</font></div>
<div><font face="Courier New"> (let/ec fail-sql</font></div>
<div><font face="Courier New"> (with-handlers
([exn:fail:sql?</font></div>
<div><font face="Courier New"> (lambda
(e)</font></div>
<div><font face="Courier New"> (let
([info (exn:fail:sql-info e)])</font></div>
<div><font face="Courier New">
(set! err-msg (cdr (assoc 'message info)))</font></div>
<div><font face="Courier New">
(fail-sql err-msg)))])</font></div>
<div><font face="Courier New"> (call-with-transaction
db thunk #:isolation 'repeatable-read))</font></div>
<div><font face="Courier New"> (disconnect db)</font></div>
<div><font face="Courier New"> err-msg)))))</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New">(define-syntax-rule (boiler-plate
db body ...)</font></div>
<div><font face="Courier New"> (boiler-plate/f (λ (db) body
...)))</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New">(let ()</font></div>
<div><font face="Courier New"> (define err-msg</font></div>
<div><font face="Courier New"> (boiler-plate</font></div>
<div><font face="Courier New"> db</font></div>
<div><font face="Courier New"> < body ... ></font></div>
<div><font face="Courier New"> ))</font></div>
<div><font face="Courier New"> ; err-msg needed here</font></div>
<div><font face="Courier New"> err-msg</font></div>
<div><font face="Courier New"> )</font></div>
<div><br>
</div>
</div>
</blockquote>
<br>
</body>
</html>