The Liskov Substitution Principle in the Rationale
Marc Nieper-WiÃkirchen 07 May 2020 08:00 UTC
In the rationale section it says:
"Because of the Liskov Substitution Principle, it is not possible to
treat [im]mutable pairs as either a subtype or a supertype of mutable
ones; they must be distinct, ..."
To make sense of this, one has to understand what is meant by subtype
or supertype in the context of Scheme and, moreover, what is meant by
the type of immutable pairs and the type of mutable pairs.
The naive answer would be that the type of immutable pairs is defined
by the collection of Scheme objects, for which the predicate `ipair?`
returns true, and the type of mutable pairs is defined by the
collection of Scheme objects, for which the predicate `pair?` returns
true. Being a subtype or a supertype would then refer to whether one
collection is sub- or a supercollection of the other.
This cannot be the answer, though, as SRFI 116 would otherwise
contradict itself: SRFI 116 recommends that quotations of pairs return
immutable pairs. As `pair?` has to return true when applied to quoted
pairs, this suggests that in these implementations, `pair?` returns
true whenever `ipair?` returns true, which would make mutable pairs a
supertype of immutable ones in this naive interpretation of "type".
Related to this question: Would it be a faithful implementation if all
the procedures exported by SRFI 116 are the same as their mutable
counterparts without the "i"-prefix? In such an implementation, there
does not seem to be any meaningful difference between pairs and
ipairs.