[plt-scheme] implementation benefits of immutable pairs

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Thu Jun 12 14:17:22 EDT 2008

Martin DeMello skrev:
> On Thu, Jun 12, 2008 at 11:02 AM, Jens Axel Soegaard
> <jensaxel at soegaard.net> wrote:
>> Martin DeMello skrev:
>>> Does making pairs immutable offer any potential for compiler
>>> optimisations? Or is it just a matter of greater code correctness?
>> http://blog.plt-scheme.org/2007/11/getting-rid-of-set-car-and-set-cdr.html
> I read that, but it seems at least intuitively possible that
> once you've crossed that bridge, you get a range of compile-time
> optimisations available to you. Googled around a bit, but couldn't
> find any papers on the topic.
Some compiler optimizations are possible. In, say,

  (let ([p (cons 1 2)])
    <something that doesn't assign to p>
    (+ (car p) (cdr p))

One can inline a version of + that omits checking whether the two
arguments are numbers.

However, making compiler optimizations possible weren't the reason for 
the shift.
The blog post mentions the reasons, improving code correctness is one 
but not the only one.

Jens Axel Søgaard

Posted on the users mailing list.