Changes between Version 9 and Version 10 of UniqueTypesSnellPym

10/31/10 18:34:13 (7 years ago)

Added optional mutation feature


  • UniqueTypesSnellPym

    v9 v10  
    5858Creates a subtype T2 of an existing encapsulation type T1. The parent type's `e` and `d` procedures must both be provided to demonstrate the caller's existing ability to construct and deconstruct the parent type (`p?` is really just a convenience, that could be crafted from `d` and a condition handler, so access to it need not be proven). The returned values are as per `make-encapsulation-type`, except that the <size> is equal to the parent's <size> plus <extra-size>; however, the definition of `make-encapsulation-type`s return values (and, therefore, the return values of `make-encapsulation-subtype`) is extended such that `p?` also returns true for encapsulations created by any subtype's `e` procedure, and `d` will work for encapsulations created by subtypes' `e` procedures, and when called on an encapsulation created by a subtype's `e` procedure, will work for indices up to `(+ <parent-size> <extra-size>)`. 
     60= Optional extension: Per-Field Mutability (append `+mutate` to your vote if you want this) = 
     63(make-mutable-encapsulation-type <mutaflags> <symbol>) 
     66Creates a mutable encapsulation type. Rather than specifying an exact integer size, the caller instead provides a list, the length of which is the number of contents (<size>). If the list entry corresponding to a content is #f, then that content is immutable; otherwise, it is mutable. 
     68An extra return value, `m!`, is returned; it is a procedure of three arguments. If the first is an encapsulation that was returned by a call to `e`, and N is an exact integer more than or equal to zero and less than <size>, and the Nth content of the encapsulation (where N is the second argument) is mutable, then the Nth content of the encapsulation is mutated to become the third argument. Otherwise, an error is signalled. 
     71(make-mutable-encapsulation-subtype <e> <d> <m!> <extra-mutaflags> [<symbol>]) 
     74If `snellpym+inheritance+mutate` wins, then you also get this extra procedure for FREE. Its semantics are what you might expect. The `extra-mutaflags` are appended onto the end of the parents' mutaflags. 
     76`m!` is an optional argument of sorts - if #f is supplied (as it is not available or the parent type isn't actually a mutable record), then the returned subtype `m!` considers all the parent contents to be immutable and can only mutate contents explicitly marked as mutable in the `extra-mutaflags` 
    6078= Rationale = 
    6280I originally specified a single "content item" in the encapsulations, suggesting that users drop a vector in there if they wanted to, but without loss of generality (and only a little loss of simplicity), implementations can easily avoid an extra indirection by providing an embedded vector for free. 
    64 I have not specified a mutation operation here, but have allowed for implementation extensions to return extra values from `make-encapsulation-type` to allow for a mutator procedure, or for implementations to provide a separate `make-mutable-encapsulation-type` etc. 
    6682I have made the encapsulation types have a hard-coded size when the type is created, in order to avoid requiring implementations to store a type descriptor *and* a length in every instance of that type. Variable-length behaviour can be had by embedding a vector created at instance creation time, if so desired.