[Top][All Lists]

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

bug#42147: 28.0.50; pure vs side-effect-free, missing optimizations?

From: Mattias Engdegård
Subject: bug#42147: 28.0.50; pure vs side-effect-free, missing optimizations?
Date: Thu, 2 Jul 2020 16:51:03 +0200

2 juli 2020 kl. 15.56 skrev Andrea Corallo <andrea_corallo@yahoo.it>:

> Well is cons allocation a semantically visible effect then?  How is it
> different?

Conses are mutable and thus each have their own identity. Numbers are immutable 
and have none; there is no defined way to distinguish two numbers that have the 
same value ('eq' does not give well-defined results). The compiler is free to, 
and does, deduplicate equal bignums. For instance, try

(disassemble (lambda () (list 18723645817263338474859 18723645817263338474859)))

and you will see that the resulting code will only contain one instance of the 

> I thought the reason why cons is not constant folded is to respect the
> allocation side effect, at least that's what I convinced my-self of :)

Yes, in the sense that

 (defun f () (cons 'a 'b))

produces a fresh (a . b) each time (f) is called, because the returned values 
can be distinguished both explicitly by 'eq' and by mutating it and observing 
whether the change affects previously returned values or not. Neither works for 

reply via email to

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