|
From: | Noah Lavine |
Subject: | Re: redo-safe-variables and redo-safe-parameters |
Date: | Tue, 26 Mar 2013 17:38:03 -0400 |
You need to combine fluids and dynamic-wind e.g.,
(define guards (make-vector 10))
(let lp ((i 0))
(when (< i 10) (vector-set! guards i (make-fluid))))
(define-syntax with-special-soft
(lambda (x)
(syntax-case x ()
((_ (x ...) code ...)
(with-syntax (((((a k) ...) (y ...))
(let loop ((i 0) (l #'(x ...)) (r '()))
(if (or (= i 10) (null? l))
(list (reverse r) l)
(loop (+ i 1) (cdr l) (cons (car l) r))))))
(with-syntax (((i ...) (iota (length #'(a ...)))))
(if (null? #'(y ...))
#'(with-fluids (((vector-ref guards i) a) ...)
(with-special* ((i a k) ...)
code ...))
#'(with-fluids (((vector-ref guards i) a) ...)
(with-special* ((i a k) ...)
(with-special-soft (y ...) code ...))))))))))
(define special-wind-guard (make-fluid (lambda (x) #t)))
(define-syntax-rule (with-special* ((i a k) ...) code ...)
(let ((last #f))
(dynamic-wind
(lambda ()
(set! last #f)
(when ((fluid-ref special-wind-guard) k)
(set! a (fluid-ref (vector-ref guards i))))
...)
(lambda ()
(call-with-values (lambda () (begin code ...))
(lambda ret
(set! last #t)
(apply values ret))))
(lambda y
(unless last
(fluid-set! (vector-ref guards i) a)
...)))))
On Tue, Mar 26, 2013 at 10:07 PM, Noah Lavine <address@hidden> wrote:
> Yes, I think parameters and fluids are the same. I was wondering if
> (with-redo-variables ...) could be a macro that expands to (with-fluids
> ...). Is that possible? It might not be.
[Prev in Thread] | Current Thread | [Next in Thread] |