From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric McDonald Newsgroups: gmane.lisp.guile.user Subject: Interesting Behavior of 'append!' In Local Context Date: Sat, 17 Oct 2009 18:28:22 -0400 Message-ID: <4ADA4506.4090804@phy.cmich.edu> 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 1255818538 14932 80.91.229.12 (17 Oct 2009 22:28:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Oct 2009 22:28:58 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Oct 18 00:28:47 2009 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 1MzHlX-0001nZ-20 for guile-user@m.gmane.org; Sun, 18 Oct 2009 00:28:47 +0200 Original-Received: from localhost ([127.0.0.1]:58009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzHlW-0007Lr-9s for guile-user@m.gmane.org; Sat, 17 Oct 2009 18:28:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MzHlH-0007LJ-OO for guile-user@gnu.org; Sat, 17 Oct 2009 18:28:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MzHlC-0007Kb-BP for guile-user@gnu.org; Sat, 17 Oct 2009 18:28:30 -0400 Original-Received: from [199.232.76.173] (port=45708 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzHlC-0007KY-6w for guile-user@gnu.org; Sat, 17 Oct 2009 18:28:26 -0400 Original-Received: from mta31.charter.net ([216.33.127.82]:50080) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MzHlB-0001iw-Qx for guile-user@gnu.org; Sat, 17 Oct 2009 18:28:25 -0400 Original-Received: from imp10 ([10.20.200.10]) by mta31.charter.net (InterMail vM.7.09.01.00 201-2219-108-20080618) with ESMTP id <20091017222823.JUQR25738.mta31.charter.net@imp10> for ; Sat, 17 Oct 2009 18:28:23 -0400 Original-Received: from [24.247.173.2] ([24.247.173.2]) by imp10 with smtp.charter.net id tyUN1c00E03U7cw05yUPrc; Sat, 17 Oct 2009 18:28:23 -0400 X-Authority-Analysis: v=1.0 c=1 a=HmMem9K8P0UA:10 a=To46UVlHYhI9Xz2gyxkA:9 a=erxVnFu2Agh9hsMUXZ8A:7 a=2FWXb73_nN0CLyGq-cDjZjj92sQA:4 User-Agent: Thunderbird 2.0.0.23 (X11/20091003) X-Enigmail-Version: 0.95.7 X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (1203?) 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:7449 Archived-At: Hi, Earlier today I ran into an interesting problem, involving the 'append!' statement modifying a local variable in Guile. I'm tempted to call it a bug, but I'm definitely not a Scheme expert and so am hoping someone can provide some enlightenment.... Suppose that I have two function definitions: guile> (define foo (lambda (p1) (let ((v1 '(-1))) (begin (append! v1 p1))))) guile> (define bar (lambda (p1) (let ((v1 (list -1))) (begin (append! v1 p1))))) I then use 'foo' as follows: guile> (foo (list "abc" "def")) (-1 "abc" "def") guile> (foo (list "abc" "def")) (-1 "abc" "def" "abc" "def") Notice that 'v1' does not seem to be re-initialized in the second invocation of 'foo'. Interestingly, if I run 'bar' with the same data, the problem does not manifest itself: guile> (bar (list "abc" "def")) (-1 "abc" "def") guile> (bar (list "abc" "def")) (-1 "abc" "def") Now, if I change the definitions of the functions to use 'set!' in conjunction with an 'append' rather than just an 'append!', then both behave as I would expect (i.e., the same as 'bar' above): guile> (define foo (lambda (p1) (let ((v1 '(-1))) (begin (set! v1 (append v1 p1)) v1)))) guile> (define bar (lambda (p1) (let ((v1 (list -1))) (begin (set! v1 (append v1 p1)) v1)))) guile> (foo (list "abc" "def")) (-1 "abc" "def") guile> (foo (list "abc" "def")) (-1 "abc" "def") guile> (bar (list "abc" "def")) (-1 "abc" "def") guile> (bar (list "abc" "def")) (-1 "abc" "def") I tried comparing the behavior with mzScheme, but it doesn't seem to have an 'append!' function. However, its output does match the tests using the set!/append versions of my functions, as expected. Any thoughts? Thanks, Eric P.S. Tested with Guile 1.8.5 and 1.8.7. Could not test with Guile from Git repo, because the built executable had a fatal error on startup.