<div dir="ltr">skipped? = #t can only arise if some struct type in the hierarchy is opaque, which would mean struct? returns #f. If you only care about types that satisfy struct?, you should be able to safely ignore skipped?, if I understand it correctly.<br>
</div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Sat, Jan 25, 2014 at 6:07 PM, Greg Hendershott <span dir="ltr"><<a href="mailto:greghendershott@gmail.com" target="_blank">greghendershott@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">> flaw: If an immutable struct is derived from a mutable one, my<br>
> predicate will (as written) incorrectly report it as immutable.<br>
> Instead I need to walk the chain of super-types, and check that all<br>
> are immutable. I'll work on this more...<br>
<br>
</div>Here's where I ended up for now.<br>
<br>
Although I don't understand how/when/why skipped? = #t would arise,<br>
I'm pretty sure that if it does arise, I can't make any assertion<br>
about immutability and should err on the side of saying "no".<br>
<br>
Will sleep on this. Would welcome feedback if anyone has any.<br>
<br>
;; As documented, `immutable?` does not work with `struct`s. Define a<br>
;; predicate that does:<br>
(define (immutable-struct? v)<br>
(define-values (st skipped?) (struct-info v))<br>
(and (not skipped?) ;unless most-specific type, can't assert immutability<br>
(immutable-struct-type? st)))<br>
<br>
(define (immutable-struct-type? st)<br>
<div class="im"> (define-values (name init-field-cnt auto-field-cnt<br>
accessor-proc mutator-proc<br>
immutable-k-list<br>
super-type skipped?) (struct-type-info st))<br>
</div> ;; A struct-type is immutable if all its fields are immutable, AND<br>
;; all its super struct-types are immutable.<br>
(and (not skipped?) ;unless most-specific type, can't assert immutability<br>
<div class="im"> (= (+ init-field-cnt auto-field-cnt)<br>
(length immutable-k-list))<br>
</div> (or (not super-type)<br>
(immutable-struct-type? super-type))))<br>
<br>
(module+ test<br>
(struct mutable (fld) #:mutable #:transparent)<br>
(define m (mutable 0))<br>
(check-false (immutable-struct? m))<br>
<br>
(struct mutable:immutable mutable (fld2) #:transparent)<br>
(define m:i (mutable:immutable 0 1))<br>
(check-false (immutable-struct? m:i))<br>
<br>
(struct immutable (fld) #:transparent)<br>
(define i (immutable 0))<br>
(check-true (immutable-struct? i))<br>
<br>
(struct immutable:immutable immutable (fld2) #:transparent)<br>
(define i:i (immutable:immutable 0 1))<br>
(check-true (immutable-struct? i:i)))<br>
</blockquote></div><br></div>