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:57:20 +0200 Message-ID: References: <49dd78620807121557n5c7a1f3bs5a2c2788faca21a7@mail.gmail.com> 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 1215932259 21421 80.91.229.12 (13 Jul 2008 06:57:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Jul 2008 06:57:39 +0000 (UTC) Cc: guile-user@gnu.org To: "Neil Jerram" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jul 13 08:58:27 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 1KHvXO-0003RR-WF for guile-user@m.gmane.org; Sun, 13 Jul 2008 08:58:27 +0200 Original-Received: from localhost ([127.0.0.1]:60126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHvWW-00074E-I2 for guile-user@m.gmane.org; Sun, 13 Jul 2008 02:57:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KHvWS-000730-99 for guile-user@gnu.org; Sun, 13 Jul 2008 02:57:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KHvWR-00072D-Fc for guile-user@gnu.org; Sun, 13 Jul 2008 02:57:27 -0400 Original-Received: from [199.232.76.173] (port=40284 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHvWR-000720-AQ for guile-user@gnu.org; Sun, 13 Jul 2008 02:57:27 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:36139) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KHvWQ-0003ku-3L for guile-user@gnu.org; Sun, 13 Jul 2008 02:57:26 -0400 Original-Received: from wf-out-1314.google.com ([209.85.200.170]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KHvWN-0008KF-Sf for guile-user@gnu.org; Sun, 13 Jul 2008 02:57:24 -0400 Original-Received: by wf-out-1314.google.com with SMTP id 28so4010143wfc.24 for ; Sat, 12 Jul 2008 23:57:20 -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:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=yP/8gpjjBhHOc3jkvkn6KaFDbaLxR3Nz2guO7+gxZmQ=; b=l+ISz/FIYQgZTstBG6v0I5gkasWw27IbXYO0S0hbDCWCIZ+VTy5mybbKMXnDc/HfyN h4A7TDZ+zRpW3RjW5ZSib8n7Mfh20qBvaLW3RqdVNSmKtqw2W5anbh7tec7MHkW2W3d5 qsMy3KLpgwzBaLUpqAGN4oR2n4oqqdT6CtoJc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=ed42wuVt9hWQEaZPcyq1wcXYvGVzaBi+1Aebec0fkuCJbAwjWq3nw9nCBeYJrvM9D+ lrsfPZ19msVyUc+EWLf4EApfIrIdLsCe9sP7FI4rWl1V+XJqRqJv+owv8jS9rCoYcqSJ mRoHeck23QRlFkuk0scQcZluVn2xHMP+bMlLQ= Original-Received: by 10.142.127.10 with SMTP id z10mr3765822wfc.53.1215932240336; Sat, 12 Jul 2008 23:57:20 -0700 (PDT) Original-Received: by 10.142.141.17 with HTTP; Sat, 12 Jul 2008 23:57:20 -0700 (PDT) In-Reply-To: <49dd78620807121557n5c7a1f3bs5a2c2788faca21a7@mail.gmail.com> Content-Disposition: inline X-detected-kernel: by mx20.gnu.org: Linux 2.6 (newer, 2) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. 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:6649 Archived-At: > Hi Maciek, > > Just picking up another point from your original email. You may have > already worked this out, but just in case... OK, it's always good to say to much than not to say enough (at least if it comes to hacking ;]) >> Additionaly, it would be nice to see the possibility >> of explicit definitions of environments, like: >> >> (define env (make-closure (a . 1)(b . 2)) >> (with env (define c 3)) > > This is equivalent to: > (define env (let ((a 1) (b 2)) (the-environment))) > (local-eval '(define c 3) env) > > except that the last line fails with a "Bad define placement" error. > That's because there are special rules for defines inside lexical > scopes. As the practise shows, although guile documentation says something different. In section 3.1.4.7 (A Shared Persistent Variable) "An important detail here is that the `get-balance' and `deposit' variables must be set up by `define'ing them at top level and then `set!'ing their values inside the `let' body. Using `define' within the `let' body would not work: this would create variable bindings within the local `let' environment that would not be accessible at top level." So one might conclude that it _is_ possible to use define inside a 'let' form. >> so that we could define the aforementioned >> counter as: >> (define counter-env (make-closure (c . 0))) >> (define ++ (with counter-env (lambda()(set! c (1+ c))c))) > > This one really works: > > (define counter-env (let ((c 0)) (the-environment))) > (define (++) (local-eval '(begin (set! c (+ c 1)) c) counter-env)) > > So, in summary, make-closure wouldn't provide anything more than what > we already have. Yes, since there's local-eval and the-environment, everything I've ever dreamed of is possible :) But as I've concluded from the discourse, neither of these is defined in R5RS (and it makes me wonder)