From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Neil Jerram" Newsgroups: gmane.lisp.guile.user Subject: Re: Closure? Date: Sun, 13 Jul 2008 23:56:48 +0100 Message-ID: <49dd78620807131556u78b6a3bah9f34e12a5c60c41f@mail.gmail.com> 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 1215989825 2029 80.91.229.12 (13 Jul 2008 22:57:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Jul 2008 22:57:05 +0000 (UTC) Cc: guile-user@gnu.org To: "Maciek Godek" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jul 14 00:57:52 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 1KIAVr-0007Tz-Mi for guile-user@m.gmane.org; Mon, 14 Jul 2008 00:57:51 +0200 Original-Received: from localhost ([127.0.0.1]:49886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIAUz-0004hi-L5 for guile-user@m.gmane.org; Sun, 13 Jul 2008 18:56:57 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KIAUv-0004fK-9U for guile-user@gnu.org; Sun, 13 Jul 2008 18:56:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KIAUt-0004d9-Kc for guile-user@gnu.org; Sun, 13 Jul 2008 18:56:52 -0400 Original-Received: from [199.232.76.173] (port=48697 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KIAUt-0004co-F4 for guile-user@gnu.org; Sun, 13 Jul 2008 18:56:51 -0400 Original-Received: from rv-out-0708.google.com ([209.85.198.248]:4463) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KIAUs-0002Ex-U5 for guile-user@gnu.org; Sun, 13 Jul 2008 18:56:51 -0400 Original-Received: by rv-out-0708.google.com with SMTP id k29so5253935rvb.6 for ; Sun, 13 Jul 2008 15:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.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=RZOXeIqGA0c0bBGZz8GzEpq4LOw6+XPowBZzdgNDCow=; b=fdBP4fmaitQVxCeA2HV63+/SbO1N/x3YmMyVnk9lkhqbsh1QTR0fhMg5cXp0lI8cKL Z02A3kGkCSvHsx8qMfV6K0ZTAluL+ySHViJQCC2USWHip42xjKFoGoNRVC6SWP2xvUBM o4wmOSAuOzkiuBBqUkiB37JR8pjA70lJNDvEo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.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=gyWVfFGmuZfIYPXqpFymia3aUpgz5DVzL3q9iatrui8su0e1/jDGDpCLoG6Um8F5XS hoPyY4D5trupBHXtI4YpsQ4wPpDjZfcyNfeME5wf+NRH9zVcf1CC2x146kMK/mH3GL1y HSACfYkVqOwbl9h2uMYdQgG+K7xZnUpeyCXww= Original-Received: by 10.114.210.2 with SMTP id i2mr16900603wag.18.1215989808989; Sun, 13 Jul 2008 15:56:48 -0700 (PDT) Original-Received: by 10.114.197.8 with HTTP; Sun, 13 Jul 2008 15:56:48 -0700 (PDT) In-Reply-To: Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) 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:6654 Archived-At: 2008/7/13 Maciek Godek : >> 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. Which would be correct! For example: (let ((a 1)) (define b 2) (+ a b)) => 3 Whereas: (let ((a 1)) (display a) (newline) (define b 2) (+ a b)) => ERROR: Bad define placement The "special rules" are just that any defines have to come before anything else in the body of the let. I don't know exactly how it works out that using a define in local-eval falls foul of the define placement rule, but it is not hard to imagine that it could do. > 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) Well I've never thought this through before, but perhaps that is because in many cases it is equivalent to create a lambda at the point where you would call the-environment, containing the code that you would later pass to local-eval. For example, the ++ example then becomes: (define ++ (let ((c 0)) (lambda () (begin (set! c (+ c 1)) c)))) - which is the traditional way of writing this example. Regards, Neil