From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: Self-evaluating function and closure Date: Sat, 15 Jun 2019 20:36:34 -0400 Message-ID: <87d0je4b82.fsf@netris.org> References: <20190612202929.GA20126@newvzh.lokolhoz> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="151643"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jun 16 02:40:30 2019 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hcJDh-000dIG-OB for guile-user@m.gmane.org; Sun, 16 Jun 2019 02:40:29 +0200 Original-Received: from localhost ([::1]:37110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcJDg-0003bx-4t for guile-user@m.gmane.org; Sat, 15 Jun 2019 20:40:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48572) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcJCM-0003ba-Ka for guile-user@gnu.org; Sat, 15 Jun 2019 20:39:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcJCK-00084r-UP for guile-user@gnu.org; Sat, 15 Jun 2019 20:39:06 -0400 Original-Received: from world.peace.net ([64.112.178.59]:50646) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hcJCJ-0007xb-3l for guile-user@gnu.org; Sat, 15 Jun 2019 20:39:03 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hcJC4-0005LB-GU; Sat, 15 Jun 2019 20:38:48 -0400 In-Reply-To: <20190612202929.GA20126@newvzh.lokolhoz> (Vladimir Zhbanov's message of "Wed, 12 Jun 2019 23:29:29 +0300") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:15554 Archived-At: Hi Vladimir, Vladimir Zhbanov writes: > Greetings, > > I have tried almost a textbook example with Guile 2.2.4: > > scheme@(guile-user)> (define (function-generator) > (let ((func #f)) > (lambda () (set! func (let a () a)) func))) > > scheme@(guile-user)> (define x (function-generator)) > scheme@(guile-user)> (define y (function-generator)) > scheme@(guile-user)> x > $20 = #:562:25 ()> > scheme@(guile-user)> y > $21 = #:562:25 ()> > scheme@(guile-user)> (x) > $22 = # > scheme@(guile-user)> (y) > $23 = # > scheme@(guile-user)> (eq? (x) (y)) > $24 = #t > > The result is unexpected for me, I expected a new self-evaluating > procedure every time I run the function-generator procedure (and > it works differently with Guile 2.0, IIUC, cannot check just now). Why would you expect 'eq?' to return #false here? Do you know of any text in Guile's manual, or in any of the relevant Scheme standards, that would lead you to expect this? Since (let a () a) contains no free variable references, every procedure returned by (let a () a) is operationally equivalent to every other procedure returned by it. Therefore, as I understand it, a conforming Scheme implementation is permitted (but not required) to return the same procedure object every time. I just refreshed my memory of the requirements of the R5RS, R6RS, and R7RS on 'eq?' when applied to procedures. Conforming implementations are required to return #true if the procedures have the same "location tags", and are required to return #false if the procedures would behave differently (return different value(s) or have different side effects) for some arguments. > AFAICS, Guile creates a toplevel procedure "a" while it should not do >so. > > scheme@(guile-user)> a > $25 = #:422:25 ()> If this were the case, it would certainly be a bug. However, I cannot reproduce it, and I strongly suspect that you had defined 'a' as a toplevel variable earlier in your Guile session and forgot about it. Mark