<HTML><BODY><span class="p">It is not writing, but reading. I'm making uinversal library for binary data (like dbf, mp3 id3 tags, and so on)  mapping to objects<br>https://github.com/Kalimehtar/binary-class<br><br>read-object simply<br><br>(</span><span class="k">define </span><span class="p">(</span><span class="nf">read-object</span> <span class="nv">binary-class</span> <span class="nv">in</span> <span class="o">.</span> <span class="nv">args</span><span class="p">)</span><div class="line" id="LC25">    <span class="p">(</span><span class="nf">send</span> <span class="p">(</span><span class="nb">apply </span><span class="nv">make-object</span> <span class="nv">binary-class</span> <span class="nv">args</span><span class="p">)</span> <span class="nv">read</span> <span class="nv">in</span><span class="p">))</span></div><br>But I don't like, that contract may not give correct error message for wrong nomber of items in args.<br><br><br>Thu, 5 Jun 2014 12:31:49 -0400 от Matthias Felleisen <matthias@ccs.neu.edu>:<br>
<blockquote style="margin: 10px; padding: 0px 0px 0px 10px; border-left-color: rgb(8, 87, 166); border-left-width: 1px; border-left-style: solid;">
        <div>
        



    









        
        


        
        
        
        
        

        
        

        
        



<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div>
                <base href="https://e.mail.ru/" target="_self">
                
                        <div id="style_14019859110000000931_BODY"><br>
Do you control the writing of objects to a port? If so, check out 'serialization.' If not, I don't think I can help you. Sorry -- Matthias<br>
<br>
<br>
<br>
On Jun 5, 2014, at 12:29 PM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
<br>
> I don't control class creation.<br>
> I need to make a wrapper around make-object and attach contract to the wrapper.<br>
> <br>
> Now I have<br>
> (provide/contract<br>
>   [read-object (->i ([binary-class (implementation?/c binary<%>)]<br>
>                         [port input-port?])<br>
>                        #:rest [args list?]<br>
>                        [result (binary-class) (is-a?/c binary-class)])])<br>
> <br>
> I cannot control number of args. Now, when error encountered I have confusing error message mentioning "instantiate".<br>
> <br>
> Thu, 5 Jun 2014 12:13:26 -0400 от Matthias Felleisen <<a href="/compose?To=matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>>:<br>
> <br>
> Here is the pattern I recommend: <br>
> <br>
> Welcome to Racket v6.0.1.11.<br>
> > (define (create-c #:x [x 0]) (new c% [x x]))<br>
> > (define c% (class object% (init-field x) (super-new)))<br>
> <br>
> That is, a class comes with a 'factory' definition, a function that creates instances and uses keywords similar to those used by the class initializer. If you then export these factories, you can enforce invariants and also probe the factory for the information you want: <br>
> <br>
> > (create-c)<br>
> (object:c% ...)<br>
> > (create-c #:x 10)<br>
> (object:c% ...)<br>
> > (procedure-arity create-c)<br>
> 0<br>
> > (procedure-keywords create-c)<br>
> '()<br>
> '(#:x)<br>
> <br>
> <br>
> Yes, one could argue that this is a poor man's substitute for missing class reflection. -- Matthias<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> On Jun 5, 2014, at 11:32 AM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
> <br>
> > For any procedure I can use procedure-arity. But how to get the number of init arguments for a class?<br>
> > <br>
> > Or maybe there are any other way to make a contract, like in Guide 7.3.9, where one can compare number of arguments and arity of the function, but when using (make-object someclass ...)<br>
> > instead of the function.<br>
> > <br>
> > <br>
> > -- <br>
> > Roman Klochkov<br>
> > ____________________<br>
> > Racket Users list:<br>
> > <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
> <br>
> <br>
> <br>
> -- <br>
> Roman Klochkov<br>
<br>
</div>
                        
                
                <base href="https://e.mail.ru/" target="_self">
        </div>

        
</div>


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