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.
