Subject: Re: bug#40693: 28.0.50; json-encode-alist changes alist

From: "Basil L. Contovounesios" <[email-masked]>
Date: Sun, 19 Apr 2020 01:33:55 +0100

Michael Heerdegen <[email-masked]> writes:

> Why?  Isn't this a classical example of modifiable code?  After some
> iterations
>
> (symbol-function 'fun-withdraw)
>
> =>
>
> (closure
>  (t)
>  (amount)
>  (json-encode-alist
>   (cons
>    (cons 'tamount amount)
>    '((const . some-constant)
>      (tamount . 12)
>      (tamount . 12)
>      (tamount . 12)))))
>
> So the problem is in the implementation of `fun-withdraw', not in that
> of `json-encode-alist' or `sort'.
>
> I mean, it's really an example of an ugly trap, but how is
> `json-encode-alist' different from other functions working with lists
> that would exploit the same problem?

A library function that encodes arbitrary Elisp objects as JSON
shouldn't destructively modify its argument; it should be possible to
call json-encode on the same object twice and get the same result.

-- 
Basil