Re: either-guard reference implementation Marc Nieper-WiÃkirchen 11 Aug 2020 08:14 UTC
Am So., 9. Aug. 2020 um 15:10 Uhr schrieb John Cowan <firstname.lastname@example.org>: >> third-party code in question >> will usually not be written using ipairs and texts but pairs and >> strings. > > > That is true, and it would certainly be more convenient if procedures accepting pairs also accept ipairs as well. However, I believe that putting such a requirement on implementers of SRFI 116 (which would make it unportable) will hinder and not help adoption. SRFI 116 leads the horse to water but cannot compel him to drink. Standard pair procedures already accept immutable pairs in the form of datum literals. Just drop "ipair?" from SRFI 116 and the route to adoption is easy. And some implementations will actually drink the water offered and make some pairs truly immutable (as many implementations already do for pair literals). >> - There are conceptually immutable data structures (for which I can >> use, say, ordinary pairs), but there aren't de facto immutable data >> structures in view of the existence of record inspection and other >> implementation-dependent low-level procedures (so there no total >> safety against buggy code). > > > There is no such thing as "total safety". There may be low-level procedures that permit altering the bits of bignums, but we don't normally defend against this by making copies of them before passing them to unknown code; indeed, I know of no language with a "number-copy" procedure. > > In any case, R6RS signals an error if any attempt is made to retrieve the mutator of an immutable field. SRFI 99 is less definite about it, but I believe it is implied by the use of "immutable" there. My point wasn't so much about the practicability or the probability of mutation of data structures declared as immutable in one way or the other; I wanted to stress the fact that we have been confusing two meanings of immutability all the time, which, in particular, led to the IMHO suboptimal SRFI 116: (1) Conceptual Immutability. (2) Actual immutability. >> For the time being, >> I think that the best backward-compatible solution is that we have >> mutable and immutable strings (whose immutability is nothing that the >> implementation is enforced to enforce) > > > Then it is useless from the risk-mitigation viewpoint. Not at all, I think. Implementations will, of course, be encouraged to detect the mutation of an immutable string as much as they are encouraged to detect when, say, "car" is applied to a number. From a risk-mitigation viewpoint, you won't choose an implementation that is silent on "(car 0)" either. We can expect that most quality implementations will detect the error once they have found time to adopt immutable strings, vectors and pairs. The good thing with this approach is that all existing code will still work. And code that claims to not mutate an input data structure can be fed such immutable data (or a good implementation will complain).