From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Kjetil S. Matheussen" Newsgroups: gmane.lisp.guile.user Subject: Re: Closure? Date: Fri, 11 Jul 2008 19:42:40 +0200 (CEST) Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7BIT X-Trace: ger.gmane.org 1215798252 18715 80.91.229.12 (11 Jul 2008 17:44:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 11 Jul 2008 17:44:12 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jul 11 19:44:59 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 1KHMfx-0006M6-J7 for guile-user@m.gmane.org; Fri, 11 Jul 2008 19:44:57 +0200 Original-Received: from localhost ([127.0.0.1]:43306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHMf5-0000FE-US for guile-user@m.gmane.org; Fri, 11 Jul 2008 13:44:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KHMf0-0000Cm-BY for guile-user@gnu.org; Fri, 11 Jul 2008 13:43:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KHMez-0000CI-Pk for guile-user@gnu.org; Fri, 11 Jul 2008 13:43:58 -0400 Original-Received: from [199.232.76.173] (port=42914 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHMez-0000CB-EK for guile-user@gnu.org; Fri, 11 Jul 2008 13:43:57 -0400 Original-Received: from smtp.getmail.no ([84.208.20.33]:39829) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KHMez-0005iN-Gd for guile-user@gnu.org; Fri, 11 Jul 2008 13:43:57 -0400 Original-Received: from pmxchannel-daemon.no-osl-m323-srv-004-z2.isp.get.no by no-osl-m323-srv-004-z2.isp.get.no (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) id <0K3U0050TRWY7400@no-osl-m323-srv-004-z2.isp.get.no> for guile-user@gnu.org; Fri, 11 Jul 2008 19:43:46 +0200 (CEST) Original-Received: from smtp.getmail.no ([10.5.16.1]) by no-osl-m323-srv-004-z2.isp.get.no (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) with ESMTP id <0K3U00IEQRV9G3A0@no-osl-m323-srv-004-z2.isp.get.no> for guile-user@gnu.org; Fri, 11 Jul 2008 19:42:45 +0200 (CEST) Original-Received: from cm-84.215.136.96.getinternet.no ([84.215.136.96]) by no-osl-m323-srv-004-z1.isp.get.no (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) with ESMTP id <0K3U00CKLRV9J541@no-osl-m323-srv-004-z1.isp.get.no> for guile-user@gnu.org; Fri, 11 Jul 2008 19:42:45 +0200 (CEST) In-reply-to: X-X-Sender: kjetil@ttleush X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) 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:6642 Archived-At: Ludovic Court?s: > "Maciek Godek" writes: > >> I've been wondering if there's any way to recall >> (or get inside) an environment of a closure (= to >> directly access variables bound to a closure) > > Yes, with `the-environment': > > guile> ((lambda (a b) (the-environment)) 2 3) > (((a b) 2 3) #) > > But don't do that, since the representation of environments could > eventually change. > Please don't change it. :-) It's one of those things which makes Guile special. Maciek Godek: > > Don't worry, I won't :) > Now I only know how to obtain environment of a closure, > but I still don't know how to get inside and modify it (I'm > lacking this `with' I wrote about). > The function "local-eval" is probably what you want. I use local-eval a lot, it's one of the really really nice features provided by Guile: (define-macro (with env . code) `(local-eval (quote (begin ,@code)) ,env)) (define ++ (let ((c 0)) (c-display "env" (the-environment)) (lambda() (set! c (1+ c)) c))) (++) => 1 (with (procedure-environment ++) (set! c 20)) (++) => 20