[plt-scheme] The case for mutable pairs (or not)
I've been thinking lately about what reasons there might be for
retaining mutable pairs. Other than the legacy code issue, it occurs to
me that a simple reason for allowing mutablle pairs is that lists are
often used in lieu of structures to represent complex objects. I've
found that in my own code I prefer to use structures, knowing that they
can easily be implemented in R5RS Scheme if need be. I find that they
make code easier to read and understand (though I still haver my share
of cadr's, and the like). But what if set-car! and set-cdr! were never
used, and mutation always involved structures? A *possible* strategy (I
haven't really thought this through) would be to implement "mutatators"
by copying, and then have accessors go to the new copy (while retainig
the same structure name). This could be tricky, though, without some
kind of write-through because the accessors would need to know that the
cached values are dirty, and that a fresh address is needed. If
mutation is rare enough, it might be acceptable to wait until all
threads have been notified that it has occured. Without this type of
mutation, programmers would need to adopt a significantly different
style, which may be necessary, but it isn't a small thing.
===
Gregory Woodhouse <gregory.woodhouse at sbcglobal.net>
"It is foolish to answer a question that
you do not understand."
--G. Polya ("How to Solve It")