From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Clinton Ebadi Newsgroups: gmane.lisp.guile.user Subject: Re: Me no understand scoping Date: Tue, 29 Jul 2008 23:24:59 -0400 Message-ID: <87r69ccaus.fsf@unknownlamer.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217388330 5768 80.91.229.12 (30 Jul 2008 03:25:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Jul 2008 03:25:30 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 30 05:26:15 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 1KO2KI-0002PY-Oj for guile-user@m.gmane.org; Wed, 30 Jul 2008 05:26:11 +0200 Original-Received: from localhost ([127.0.0.1]:44096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KO2JO-0007Tb-Ay for guile-user@m.gmane.org; Tue, 29 Jul 2008 23:25:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KO2JK-0007S4-Dw for guile-user@gnu.org; Tue, 29 Jul 2008 23:25:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KO2JJ-0007QS-1l for guile-user@gnu.org; Tue, 29 Jul 2008 23:25:09 -0400 Original-Received: from [199.232.76.173] (port=38391 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KO2JI-0007QB-Rg for guile-user@gnu.org; Tue, 29 Jul 2008 23:25:08 -0400 Original-Received: from deleuze.hcoop.net ([69.90.123.67]:60322) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KO2JJ-0005iz-8s for guile-user@gnu.org; Tue, 29 Jul 2008 23:25:09 -0400 Original-Received: from cpe-071-065-238-103.nc.res.rr.com ([71.65.238.103] helo=localhost.localdomain) by deleuze.hcoop.net with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1KO2JG-0007Du-9d for guile-user@gnu.org; Tue, 29 Jul 2008 23:25:06 -0400 In-Reply-To: (Maciek Godek's message of "Tue\, 29 Jul 2008 23\:18\:05 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 1) 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:6701 Archived-At: "Maciek Godek" writes: > Hi, > consider the following code (simple iteration > construct invented mainly to cause naming > conflict, as the function 'times' is already > defined in guile) > > (define-macro (times n f) > `(let ((env (the-environment))) > (let loop ((i 0)) > (if (< i ,n) > (begin > (local-eval ,f env) > (loop (1+ i)) > ) > ) > ) > ) > ) > > the whole thing with env was made as > a workaround disallowing f to see the > i variable defined in the macro (and to > perhaps see the value that otherwise > would be shadowed) > > however, > > (times 20 (display i)) > > yields > > 012345678910111213141516171819 > > Why? `macroexpand-1' is helpful here -- (local-eval ,f env) is wrong. As a matter of style, you probably want to avoid local-eval as it will have to be removed whenever Guile ends up with a faster compiler (one day when guile-vm is integrated into core and lexical environments become fixed arrays or similar), and messing with existing lexical environments is Very Bad (tm). Avoiding all uses of eval and, by extension, local-eval is a good idea. -- The hubbub of the waking life might close a door which in the dreamy Subliminal might remain ajar...