2014-12-20 8:39 GMT+01:00 Marco Maggi <[email protected]>: > > > The problem is that ASSQ-SET! mutates the result of the literal > expression: > > '((name . <name>) (title . #f)) > > this problem is not related to SYNTAX-RULES. The form: > > '((name . <name>) (title . #f)) > > is a "literal expression", it is an expression that evaluates to the > datum: > > ((name . <name>) (title . #f))
To be precise, in the particular context of the macro definition, <name> is a macro parameter, so the assoc is not a literal, but a form that will get expanded to a literal during macro expansion. In particular, it should get expanded to '((name . one) (title . #f)) from the first usage, and '((name . two) (title . #f)) from the second usage. By the way, I don't know guile internals, but I think the optimization (i.e. the assumption that both literal objects can be considered a single object) happens during compilation: if you evaluate the form (begin (sect one (title "Section One")) (sect two (title "Section Two"))) then you'll get the aforementioned unexpected behaviour, but if you evaluate each macro separately, everything will remain to behave properly. So I don't think that any additional bit would be needed to mark whether an object is mutable or immutable: the compiler could check if any mutating procedure is called on an object before it considers it to be eq? with another equal? object from the context of an expression.
