Re: Use of a counter in a list

Michał "phoe" Herda via Sbcl-help <[email protected]>
Newsgroups gmane.lisp.steel-bank.general
Message-ID <[email protected]>
Modifying constants, such as quoted lists, such as '(0), is undefined 
behavior.

Do (let ((a (list 0)) ...) instead.

W dniu 2024-05-14 11:29, steph.tougard via Sbcl-help napisał(a):

> Hi,
> 
> I don't understand why this code does not work with SBCL while it works 
> perfectly with ABCL and CLISP
> 
> (let ((a '(0)))
> (defun inc-a () (incf (car a)))   (defun a () (car a)))
> 
> On SBCL
> 
> CL-USER> (a)
> 0 (0 bits, #x0, #o0, #b0)
> CL-USER> (inc-a)
> 1 (1 bit, #x1, #o1, #b1)
> CL-USER> (a)
> 0 (0 bits, #x0, #o0, #b0) CL-USER>
> 
> On CLISP or ABCL
> 
> [2]> (a)
> 0
> [3]> (inc-a)
> 1
> [4]> (a)
> 1 [5]>
> 
> Even more worrying to me, I get the same result with 
> (sb-ext:atomic-incf), the (a) function always returns 0.
> 
> Please, can you explain to me like I'm 5 years old why it does not work 
> on SBCL and why it works with other LISP compilers ?
> 
> _______________________________________________
> Sbcl-help mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sbcl-help

_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.