<HTML><BODY>So you mean, that struct should be only struct, not like Common Lisp CLOS or C++ classes, that are "anything with fields".<br><br>Then I need an advice. I want to make persistent structs. There are several options:<br><br>1) Build "`struct?' with #:reader and #:writer options". Then I have to make a struct, redefine accessors and mutators and somehow tell (match ...) that it is not genuine struct (I don't know, how to redefine syntax).<br><br>2) Build my own persistent-struct, that is not `struct?'. Then it cannont be used where strut? may be used and I have to write own match-expander.<br><br>3) Don't mimic struct. Maybe classes.<br><br>What would you advice? What is more correct?<br><br><br>Tue, 19 Aug 2014 09:35:48 -0400 от Sam Tobin-Hochstadt <samth@cs.indiana.edu>:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
        <div id="">
        



    









        
        


        
        
        
        
        

        
        

        
        



<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div>
                <base target="_self" href="https://e.mail.ru/">
                
                        <div id="style_14084553690000001016_BODY">On Tue, Aug 19, 2014 at 8:32 AM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
> #lang racket<br>
> (require (for-syntax racket racket/struct-info))<br>
> (struct foo (a b))<br>
> (set! foo-a (let ([old foo-a])<br>
>                           (λ (x) (displayln x) (old x))))<br>
> (define t (foo 1 2))<br>
><br>
> (displayln "Before change")<br>
> (match t [(foo a b) a])<br>
<br>
In this code, `match` looks at `foo`, and sees that it's definitely a<br>
struct descriptor created by `struct`, and so that it knows that `t`<br>
will really be an instance of `foo`. Then it generates code that uses<br>
`unsafe-struct-ref` to extract the fields. That's why it never uses<br>
the modified `foo-a`.  To check this, it uses the<br>
`checked-struct-info?` predicate.<br>
<br>
><br>
> (let-syntax ([foo (extract-struct-info (syntax-local-value #'foo))])<br>
>    (displayln "After change")<br>
>    (match t [(foo a b) a]))<br>
<br>
In this code, `match` can't be sure that `foo` refers to a real<br>
struct, so it just treats the struct info as describing some<br>
procedures and a predicate, and it generates the "obvious" code, which<br>
calls `foo-a`, which you've modified.<br>
<br>
I could change `match` so that it also uses<br>
`variable-reference-mutated?` for all of the identifiers where it uses<br>
checked struct info, and so behaves the same in both cases. However,<br>
I'd prefer to reject the first program instead, by hiding `foo-a`<br>
behind a macro that rejects assignment.<br>
<br>
Sam<br>
</div>
                        
                
                <base target="_self" href="https://e.mail.ru/">
        </div>

        
</div>


</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>