guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: perplexing syntax-rules bug


From: Wette, Matthew R (3441)
Subject: Re: perplexing syntax-rules bug
Date: Sat, 20 Dec 2014 14:37:25 +0000

On Dec 19, 2014, at 11:39 PM, Marco Maggi <address@hidden> wrote:

> Wette, Matthew R (3441) wrote:
> 
>> 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
> 
> (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)))))
> 
> The  problem  is  that  ASSQ-SET!  mutates the  result  of  the  literal
> expression:
> 
>   '((name . <name>) (title . #f))
> 
> 
>  To solve the problem you have to replace:
> 
>   '((name . <name>) (title . #f))
> 
> with:
> 
>   (list (cons 'name <name>) (cons 'title #f))
> 

OK.  Thanks.   I'm guessing list-copy would be another option: (sval (list-copy 
'((a . 1) (b . 2)))

Matt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]