[plt-scheme] Mutable and immutable pairs in PLT Scheme

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Nov 25 20:03:41 EST 2008

At Wed, 26 Nov 2008 11:44:58 +1100, Andrew Reilly wrote:
> I've just re-read Matthew's blog entry, as Robby suggested, and
> I regret that I didn't "get" why the type of mcons couldn't be a
> sub-type of cons

To get the reasoning benefits of immutable pairs, functions generally
need to insist that they're given immutable pairs. We could change all
the `pair?' tests to `immutable-pair?' and all the `list?' tests to
`immutable-list?', but we'd want to change the vast majority of them.
So, instead, we changed `pair?' and `list?' to mean the immutable
versions, and we switched to `mpair?' and `mlist?' in the very few
places where we really wanted mutable pairs.

> However, given the result of the PLT4.0
> experiment, wouldn't it be possible for PLT-hosted R6RS
> libraries to have switchable behaviour with respect to cons
> cells, depending on whether or not they import the set-car!
> and set-cdr! functions?  That is, one would expect that most
> modern R6RS libraries would *not* import these, and so could
> happily assume immutable cons behaviour, and so could happily
> interact with #lang/scheme modules on an equal footing?

Yes, we have long planned (but still not found the time to implement) a
way to import R6RS source as if it were "R6iRS" source --- where
"R6iRS" is an imaginary language just like R6RS, except with only
immutable pairs.


Posted on the users mailing list.