From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Lavine Newsgroups: gmane.lisp.guile.devel Subject: Re: redo-safe-variables and redo-safe-parameters Date: Tue, 26 Mar 2013 17:38:03 -0400 Message-ID: References: <13378334.Jv25yq6OaM@warperdoze> <4099741.BPvjEG9t1k@warperdoze> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec51dd609a9f94d04d8dabd81 X-Trace: ger.gmane.org 1364333913 14951 80.91.229.3 (26 Mar 2013 21:38:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Mar 2013 21:38:33 +0000 (UTC) Cc: guile-devel To: Stefan Israelsson Tampe Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Mar 26 22:38:59 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UKba2-0004XW-Pl for guile-devel@m.gmane.org; Tue, 26 Mar 2013 22:38:55 +0100 Original-Received: from localhost ([::1]:44404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKbZe-0004Bh-PL for guile-devel@m.gmane.org; Tue, 26 Mar 2013 17:38:30 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKbZa-0004BX-61 for guile-devel@gnu.org; Tue, 26 Mar 2013 17:38:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKbZY-0001ea-Nl for guile-devel@gnu.org; Tue, 26 Mar 2013 17:38:26 -0400 Original-Received: from mail-pd0-f175.google.com ([209.85.192.175]:33449) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKbZY-0001eQ-BC for guile-devel@gnu.org; Tue, 26 Mar 2013 17:38:24 -0400 Original-Received: by mail-pd0-f175.google.com with SMTP id t10so998339pdi.20 for ; Tue, 26 Mar 2013 14:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=Ky0hlFPjxplD4iRwfd8NDzkqRZAEs0xk9S9Y9ABfAkI=; b=0niXjYvj+zZbTC31lmDyeIksfUIFLQ0rvnDzl1vRFSEdrdTBrxg5mHUIvkOGtr0p/m fsfZYeu7AlCo2FemGC33D4end/3UTnXRsgLc7df97bY5k8NxCY5CI7pwlZa/EZsym7kt KfstLyzG1gNBl8ucIrFF9b3Sbi90p1JNkD9Ks768OZKI/8u40RDwqLE67To/KrwF771v bEswZURn85AIPTF8VhfsIRbJZaOSSbF3u0hhQYpO4wgHdOCaGpJCa8Qh0OgB3/wJCb8i w4wF0v5qLn09IrHwerWmvnzLbUNolqC0Q5uOmpnjpmOF5iF97e7Z9sp14V2oWNB8KF5Z QQwA== X-Received: by 10.66.21.72 with SMTP id t8mr8092400pae.53.1364333903343; Tue, 26 Mar 2013 14:38:23 -0700 (PDT) Original-Received: by 10.68.157.42 with HTTP; Tue, 26 Mar 2013 14:38:03 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: 9-U4g4UjuigWpGryrCoeLvq0pZY X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.192.175 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16005 Archived-At: --bcaec51dd609a9f94d04d8dabd81 Content-Type: text/plain; charset=ISO-8859-1 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 < stefan.itampe@gmail.com> 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 > 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. > --bcaec51dd609a9f94d04d8dabd81 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Okay. Let me see if I understand this corre= ctly:

Let's say, hypothetically, that there were variables= that worked exactly like fluids except that you could reference them by si= mply 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-le= t variables behave? (There's also a nice example on that page of how fl= uid-let works with continuations.)

Best,
Noah

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


On Tue,= Mar 26, 2013 at 5:13 PM, Stefan Israelsson Tampe <stefan.itampe@gma= il.com> wrote:
You need to combine fluids and dynamic-wind = e.g.,


(define guards (make-vector 10))
(let lp ((i 0))
=A0 (when (< i 10) (vector-set! guards i (make-fluid))))

(define-syntax with-special-soft
=A0 (lambda (x)
=A0 =A0 (syntax-case x ()
=A0 =A0 =A0 ((_ (x ...) code ...)
=A0 =A0 =A0 =A0(with-syntax (((((a k) ...) (y ...))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (let loop ((i 0) (l #'(x ..= .)) (r '()))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (or (=3D i 10) (null? l= ))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (list (reverse r) l= )
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (loop (+ i 1) (cdr = l) (cons (car l) r))))))
=A0 =A0 =A0 =A0 (with-syntax (((i ...) (iota (length #'(a ...)))))
=A0 =A0 =A0 =A0 =A0 =A0 (if (null? #'(y ...))
=A0 =A0 =A0 =A0 =A0 =A0 #'(with-fluids (((vector-ref guards i) a) ...)<= br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (with-special* ((i a k) ...)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0code ...))
=A0 =A0 =A0 =A0 =A0 =A0 #'(with-fluids (((vector-ref guards i) a) ...)<= br> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (with-special* ((i a k) ...)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(with-special-soft (y ...) code ...)= )))))))))

(define special-wind-guard (make-fluid (lambda (x) #t)))
(define-syntax-rule (with-special* ((i a k) ...) code ...)
=A0 (let ((last #f))
=A0 =A0 (dynamic-wind
=A0 =A0 =A0 =A0 (lambda ()
=A0 =A0 =A0 =A0 =A0 (set! last #f)
=A0 =A0 =A0 =A0 =A0 (when ((fluid-ref special-wind-guard) k)
=A0 =A0 =A0 =A0 =A0 =A0 (set! a (fluid-ref (vector-ref guards i))))
=A0 =A0 =A0 =A0 =A0 ...)
=A0 =A0 =A0 =A0 (lambda ()
=A0 =A0 =A0 =A0 =A0 (call-with-values (lambda () (begin code ...))
=A0 =A0 =A0 =A0 =A0 =A0 (lambda ret
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (set! last #t)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (apply values ret))))
=A0 =A0 =A0 =A0 (lambda y
=A0 =A0 =A0 =A0 =A0 (unless last
=A0 =A0 =A0 =A0 =A0 =A0 (fluid-set! (vector-ref guards i) a)
=A0 =A0 =A0 =A0 =A0 =A0 ...)))))


On Tue, Mar 26, 2013 at 10:07 PM, Noah Lavine <noah.b.lavine@gmail.com> 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-fluid= s
> ...). Is that possible? It might not be.

--bcaec51dd609a9f94d04d8dabd81--