Compiler bug: cons function wrongly constant folded.

 new new list compose Reply to this message Top page
+ (text/plain)
+ (text/html)

Delete this message
Author: Kaz Kylheku
To: TXR Users
Subject: Compiler bug: cons function wrongly constant folded.

Hi all,

I just noticed that when the cons function is called with constant arguments, the compiler aggressively evaluates it at compile time, as if it were a pure arithmetic operation. For instance (cons 1 2) is effectively compiled to (quote (1 . 2)).  This is incorrect because the function is relied upon to produce a fresh object which can be safely mutated. Constant folding list operations isn't something we can do casually the way (+ 2 2) can be compiled to 4.

This mistake is not made in the case of list*; (list* 1 2) compiles to a function call to that function, at any optimization level.

Cheers ...