From: Eric McDonald <mcdonald@phy.cmich.edu>
To: guile-user@gnu.org
Subject: Interesting Behavior of 'append!' In Local Context
Date: Sat, 17 Oct 2009 18:28:22 -0400 [thread overview]
Message-ID: <4ADA4506.4090804@phy.cmich.edu> (raw)
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.
next reply other threads:[~2009-10-17 22:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-17 22:28 Eric McDonald [this message]
2009-10-17 23:09 ` Interesting Behavior of 'append!' In Local Context Stephen Compall
2009-10-18 0:36 ` Eric McDonald
2009-10-18 1:45 ` Stephen Compall
2009-10-18 13:53 ` Eric McDonald
2009-10-18 10:25 ` Andy Wingo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ADA4506.4090804@phy.cmich.edu \
--to=mcdonald@phy.cmich.edu \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).