Scheme Fluidlet
(defmacro fluid-let (clauses . body)
(let ((ids (map car clauses))
(new-tmps (map (lambda (x) (gentemp)) clauses))
(old-tmps (map (lambda (x) (gentemp)) clauses)))
`(let (,@(map list new-tmps (map cadr clauses))
,@(map list old-tmps (make-list (length clauses) #f)))
(dynamic-wind
(lambda ()
,@(map (lambda (ot id) `(set! ,ot ,id))
old-tmps ids)
,@(map (lambda (id nt) `(set! ,id ,nt))
ids new-tmps))
(lambda () ,@body)
(lambda ()
,@(map (lambda (nt id) `(set! ,nt ,id))
new-tmps ids)
,@(map (lambda (id ot) `(set! ,id ,ot))
ids old-tmps))))))