From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: Special variables to relax boxing Date: Thu, 21 Mar 2013 17:28:33 +0100 Message-ID: <15679496.NB781zMOvX@warperdoze> References: <3101921.Ei70kTLzB2@warperdoze> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: ger.gmane.org 1363883380 18118 80.91.229.3 (21 Mar 2013 16:29:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Mar 2013 16:29:40 +0000 (UTC) Cc: Mark H Weaver , guile-devel To: Noah Lavine Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Mar 21 17:30:06 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 1UIiNP-0000eT-IA for guile-devel@m.gmane.org; Thu, 21 Mar 2013 17:30:03 +0100 Original-Received: from localhost ([::1]:33720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIiN2-0004HV-8K for guile-devel@m.gmane.org; Thu, 21 Mar 2013 12:29:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIiM5-0003Ab-KZ for guile-devel@gnu.org; Thu, 21 Mar 2013 12:28:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIiM3-0006Yf-O5 for guile-devel@gnu.org; Thu, 21 Mar 2013 12:28:41 -0400 Original-Received: from mail-la0-x22b.google.com ([2a00:1450:4010:c03::22b]:58671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIiM3-0006YP-Gg for guile-devel@gnu.org; Thu, 21 Mar 2013 12:28:39 -0400 Original-Received: by mail-la0-f43.google.com with SMTP id ek20so5570278lab.30 for ; Thu, 21 Mar 2013 09:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:user-agent :in-reply-to:references:mime-version:content-transfer-encoding :content-type; bh=Ija9E2xU2elr6hqA5oiA6N+Bp8OSJwj+0A1bmvkrq4Q=; b=tM5HZal35Z3nVcbbC6gGrqPg2C4Q+8B+EfE4SSAps4wuBPX3wDjDnkXTk1KGmRWBiy 8fbHjcwEKU5SrG2/313pyZamSB8NT0wZUB/qA4OqMDIgiNtp0hk3eq1ePTd7b9pyhkWG tEW2e8zCwsnvbCaGc6aAwezxBmaobGBJOmtURiRSw9PbHFl4USwg5DIpBBcFznhoot2e Ykk4UedmdAJtQgfV63kTKOkxH4v7dDXCFeTtquIqJh8XzvlgSKa16KrpVs3je51hUQab z9g2HB023O/SzfMtXqd93SbcH/S//QSxIf+Jf+c0Oy2Nz68vI+IGOxsulu1xMeiBZYuo FiXQ== X-Received: by 10.152.144.202 with SMTP id so10mr8112250lab.9.1363883318397; Thu, 21 Mar 2013 09:28:38 -0700 (PDT) Original-Received: from warperdoze.localnet (1-1-1-39a.veo.vs.bostream.se. [82.182.254.46]) by mx.google.com with ESMTPS id go12sm2713547lab.3.2013.03.21.09.28.36 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Mar 2013 09:28:37 -0700 (PDT) User-Agent: KMail/4.9.5 (Linux/3.5.0-26-generic; KDE/4.9.5; x86_64; ; ) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22b 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:15957 Archived-At: On Thursday, March 21, 2013 11:35:19 AM Noah Lavine wrote: > (lambda () > (let ((x 5)) > (set! x (compute-1 x)) > (set! x (compute-2 x)) > x)) > > becomes > > (lambda () > (let ((k1 (lambda (x) (k2 (compute-2 x)))) > (k2 (lambda (x) x))) > (k1 (compute-1 x)))) > > However, this rewriting idea runs into trouble when you try to figure > out what happens to mutable variables that have been captured by > closures (as Mark said). I don't know what the right solution is > here. The semantic is that cpatured variables in lambdas will be restored to the value when the continuation left the guard. And this is something you want many times e.g. consider, (let ((a 0) (f (case-lambda (() a) ((b) (set! a b))))) (with-special (a) (for-each (lambda (x) (if (blah x) (k x f) (abort-to-prompt 'tag a))) a-list) (f))) Assume that you would like to be able to go back to the tag abort many times in a redo/undo sequence, then it is natural for the a referenced in f to be restored as well. But as you know sometimes this is not what we want. As I said, using dynwinds and fluids it's really possible to get this behavior today but it's really a bloated solution. Anyhow the good news with this semantic is as with the current behavior of assigned variables it's easy to reason with the code although one risk some severe bugs. A good question though is what we should use as default for e.g. a python implementation where prompts is not included per se, but which we might want to add as a special scheme flavour of python using an import e.g. what is the natural thing to expect for the variables that are assigned. Also in the previous email I had a suggestion to for each with variable, a, add two slots in the stack e.g. a1 val1 s2 val2 ... But there is a good reason to asign a kind to this as well e.g. a1 val kind a2 val2 kand2 ... then we could use a predicates when we rewind a continuation e.g. at rewind: (when (pred1 kind1) (set! a1 (ref-val val1))) ... and and at wind (when (pred2 kind1) (set-val val1 a1)) ... A simple version of this with a complex implementation is what I actually use in guile-log. BTW after this deep realizations of the guile variable behavior I'm ready to implement a much improved version of these special variables in guile-log that is both efficient and featureful. Cool! Have fun /Stefan