From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Maciek Godek" Newsgroups: gmane.lisp.guile.user Subject: Re: Closure? Date: Sun, 13 Jul 2008 08:59:18 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1215932379 21615 80.91.229.12 (13 Jul 2008 06:59:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Jul 2008 06:59:39 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jul 13 09:00:26 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KHvZG-0003ob-Uh for guile-user@m.gmane.org; Sun, 13 Jul 2008 09:00:23 +0200 Original-Received: from localhost ([127.0.0.1]:59267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHvYP-0007wz-6R for guile-user@m.gmane.org; Sun, 13 Jul 2008 02:59:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KHvYK-0007wk-Gx for guile-user@gnu.org; Sun, 13 Jul 2008 02:59:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KHvYH-0007ue-V0 for guile-user@gnu.org; Sun, 13 Jul 2008 02:59:23 -0400 Original-Received: from [199.232.76.173] (port=40310 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHvYH-0007uA-Or for guile-user@gnu.org; Sun, 13 Jul 2008 02:59:21 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:36302) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KHvYH-0003st-7n for guile-user@gnu.org; Sun, 13 Jul 2008 02:59:21 -0400 Original-Received: from wf-out-1314.google.com ([209.85.200.169]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KHvYG-00009g-4P for guile-user@gnu.org; Sun, 13 Jul 2008 02:59:20 -0400 Original-Received: by wf-out-1314.google.com with SMTP id 28so4010391wfc.24 for ; Sat, 12 Jul 2008 23:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=nJTkRKEYXCEz78fKncbwtQDoqKDKF2EpJYTFrLkIMk4=; b=CpVfuISn82A3lsxc7JDPoI7wQKw5uPDV1BeDP9jYaeIA22pG4ls/QpYMEFDJdyr7AB vCj5bM/pxCdUdyJSDnFxPkAgDd9b+1L+Zfx/XYYPrJKatVy63dCsGkLeXPxuWfWhTSXF sG1Zv8Qn/PP5lwpT7bxDl6dMIwyvdpOsZV7QE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=c4NwAnnfZ0OWbhmyKxYENv+zvLKTx22Wfkqi7STZ7412PtmpfvsAmDR2LYyQaNGJ3I oLnZa9/lvoZqCGupGDkCIc8HyEX4LNPFX+P0Qq+NkJpg5f+1ig8FJsxxuWBYtW0l7iD7 jTU5x0E23V96Qwr5K8Uz9CC6FDMV0RS6K2lv0= Original-Received: by 10.143.155.7 with SMTP id h7mr3780637wfo.16.1215932359105; Sat, 12 Jul 2008 23:59:19 -0700 (PDT) Original-Received: by 10.142.141.17 with HTTP; Sat, 12 Jul 2008 23:59:18 -0700 (PDT) In-Reply-To: Content-Disposition: inline X-detected-kernel: by mx20.gnu.org: Linux 2.6 (newer, 2) X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6650 Archived-At: >> I don't actually get the line with c-display. >> Does it require any additional module? >> 'Cause it ain' workin' for me. >> (and besides what does it do? >> the remaining part works fine) >> > > Just ignore that one. c-display is just a debugging > function I forgot to remove. :-) OK, actually that's exactly what I did :D >>> (++) >>> => 1 >>> (with (procedure-environment ++) (set! c 20)) >>> >>> (++) >>> => 20 >> >> I'm really impressed :) Great respect! >> >> I only wonder if there's a way to add a new >> variable to an existing closure, or to delete one. >> (not that I need it right now; but I imagine that >> it can be implemented quite easily and efficiently >> in C if the notion of closure is well-defined and >> explicit) >> > > Adding is easy: > > (define (add-var-to-environment env name val) > (local-eval `(let ((,name ,val)) (the-environment)) > env)) > > (define env (add-var-to-environment (the-environment) 'a 50)) > > (local-eval 'a env) > => 50 Bravo! Gee, thanks a lot! > I don't know if there's possible to delete a variable > in a clean way. That's nothing urgent. The thing is that I started to perceive the global environment as a special closure (I think it could be a nice generalization) and in that model, the "define" and "undefine" forms could operate within the nearest scope, which could make the following constructs legal: (with env (define x 20)) (with env (undefine x)) That would be freakin' cool. I imagine that there could be a way to redefine "define" inside a closure env (and perhaps to invent an non-portable solution to undefine), but I'd prefer to leave this idea to the ones who implement guile's internals, so that there's only one "define" operating on different scopes. (Or maybe it only seems so simple...) Thanks once again for showing me the power of local-eval, for it's so close to what I've been looking for.