<HTML><BODY>Serialize is good for one-shot import/export.<br><br>By persistence I mean possibility to get objects from persistent storage by reference on-demand.<br><br>For example I have facebook-like site:<br>(persistent-struct user (login password photo ...))<br><br>(persistent-struct message (user text seen-by))<br><br>If i read concrete message for its text, I don't want to pull all user information for its author and list of users, that have seen the message.<br><br>Then I need to make load only references to these users. But when I write (user-login (message-user the-message)), the library must make in field user real struct from reference (and memoize it).<br><br>I tried to use impersonator, but it doesn't allow to have own fields in impersonator (and prop:impersonator-of doesn't replace accessors).<br><br>generic doesn't add accessors to fields. It only gives common function for different structs.<br><br>Tue, 19 Aug 2014 10:52:23 -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_14084599650000000400_BODY">First, for persistence, can you use either prefab structs or the<br>
serialize library?<br>
<br>
If you can't, what I'd do is implement a generic called `persist`<br>
using `racket/generic`, and then have all the structs you wanted to be<br>
persistent implement that generic.<br>
<br>
Sam<br>
<br>
On Tue, Aug 19, 2014 at 10:45 AM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
> So you mean, that struct should be only struct, not like Common Lisp CLOS or<br>
> C++ classes, that are "anything with fields".<br>
><br>
> Then I need an advice. I want to make persistent structs. There are several<br>
> options:<br>
><br>
> 1) Build "`struct?' with #:reader and #:writer options". Then I have to make<br>
> a struct, redefine accessors and mutators and somehow tell (match ...) that<br>
> 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<br>
> 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<br>
> <<a href="/compose?To=samth@cs.indiana.edu">samth@cs.indiana.edu</a>>:<br>
><br>
> 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>
><br>
><br>
><br>
> --<br>
> Roman Klochkov<br>
</div>
<base target="_self" href="https://e.mail.ru/">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>