It doesn't seem to be a bug in syntax-rules. It seems to appear whenever
two consecutive let forms are used with an assoc list argument which starts
with identical elements:
(begin
(let ((l '((a . X)(b . Y)(c . 7))))
(assoc-set! l 'b 'Z))
(let ((l '((a . X)(b . Y))))
l))
===> ((a . X) (b . Z))
It is likely that the compiler assumes that both lists can be represented
using the same storage, because it doesn't notice that the first object
gets mutated.
This qualifies for a serious bug report, but if you wish to get a quick
workaround, you can do it like this:
(define-syntax sect
(syntax-rules ()
((sect <name> <expr> ...)
(let* ((sval* '(skip ((name . <name>) (title . #f))))
(sval (cdr sval*)))
(format #t "new sect: ~a\n" (quote <name>))
(format #t " sval= ~a\n\n" sval)
(assq-set! sval 'title "ABC")
(values)))))
Thanks®ards
2014-12-19 21:14 GMT+01:00 Wette, Matthew R (3441) <
[email protected]>:
> Sorry to bug, I can't figure out why "sval" in the second evaluation of
> "sect" is bound to the "sval" from the first evaluation of "sect". Anyone
> understand? This is guile 2.0.11. -- Matt
>
> ;; bug_syntax.scm
>
>
> (define-syntax sect
>
> (syntax-rules ()
>
> ((sect <name> <expr> ...)
>
> (let ((sval '((name . <name>) (title . #f))))
>
> (format #t "new sect: ~a\n" (quote <name>))
>
> (format #t " sval= ~a\n\n" sval)
>
> (assq-set! sval 'title "ABC")
>
> (values)))))
>
>
> (sect one (title "Section One"))
>
> (sect two (title "Section Two"))
>
> > (load "bug_syntax.scm")
>
> new sect: one
>
> sval= ((name . one) (title . #f))
>
>
> new sect: two
>
> sval= ((name . two) (title . ABC))
>
>
>
>
>