guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: redo-safe-variables and redo-safe-parameters


From: Noah Lavine
Subject: Re: redo-safe-variables and redo-safe-parameters
Date: Tue, 26 Mar 2013 17:38:03 -0400

Okay. Let me see if I understand this correctly:

Let's say, hypothetically, that there were variables that worked exactly like fluids except that you could reference them by simply writing their names, instead of using (fluid-ref ...). Would those be what you want?

I was confusing our fluids and the (fluid-let ...) construct from MIT Scheme [0]. Are you looking for variables that behave the way fluid-let variables behave? (There's also a nice example on that page of how fluid-let works with continuations.)

Best,
Noah

[0] http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-ref/Dynamic-Binding.html


On Tue, Mar 26, 2013 at 5:13 PM, Stefan Israelsson Tampe <address@hidden> wrote:
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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]