<HTML><BODY>I <span class="hps">reformulate my problem:<br>I need to make a chaperone, that checks only type of first arg. Is it possible?<br><br>If yes, I'll sumply make something like<br></span>(define (arity>=/c x)<br> (λ (proc)<br> (define arity (normalize-arity (procedure-arity proc)))<br> (define max-arity<br> (if (list? arity) (car (reverse arity)) arity))<br> (or (arity-at-least? max-arity) <br> (>= max-arity x))))<br><br>(and/c (arity>=/c 2)<br> (check-first-arg input-port?))<br><br><br>Sun, 29 Jun 2014 13:08:06 -0400 от "Alexander D. Knauth" <alexander@knauth.org>:<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_14040616890000000429_BODY"><div>You can use or/c to do this, as long as you guard them like this so that no more than one contract matches at a time:</div><div><div><font face="Courier New">(or/c</font></div><div><font face="Courier New"> (and/c (procedure-has-arity/c 2) (-> input-port? any/c any))</font></div><div><font face="Courier New"> (and/c (procedure-has-arity/c 3) (-> input-port? any/c any/c any))</font></div><div><font face="Courier New"> (and/c (procedure-has-arity/c 4) (-> input-port? any/c any/c any/c any))</font></div><div><font face="Courier New"> (->* (input-port? any/c) #:rest list? any)</font></div><div><font face="Courier New"> )</font></div></div><div><br></div><div>Or, you could use if/c from unstable/contract, or define a cond/c macro like this:</div><div><div><font face="Courier New">(require unstable/contract)</font></div><div><font face="Courier New">(define-syntax cond/c</font></div><div><font face="Courier New"> (syntax-rules (else)</font></div><div><font face="Courier New"> [(cond/c) none/c]</font></div><div><font face="Courier New"> [(cond/c [else else-c])</font></div><div><font face="Courier New"> else-c]</font></div><div><font face="Courier New"> [(cond/c [pred then-c] clause ...)</font></div><div><font face="Courier New"> (if/c pred</font></div><div><font face="Courier New"> then-c</font></div><div><font face="Courier New"> (cond/c clause ...))]))</font></div></div><div><font face="Courier New"><br></font></div><div><div><font face="Courier New">(cond/c [(procedure-has-arity/c 2) (-> input-port? any/c any)]</font></div><div><font face="Courier New"> [(procedure-has-arity/c 3) (-> input-port? any/c any/c any)]</font></div><div><font face="Courier New"> [(procedure-has-arity/c 4) (-> input-port? any/c any/c any/c any)]</font></div><div><font face="Courier New"> [else (->* (input-port? any/c) #:rest list? any)])</font></div></div><div><br></div><div>By the way it has to be procedure-has-arity/c, not procedure-includes-arity/c:</div><div><div><font face="Courier New">(define (procedure-has-arity/c arity)</font></div><div><font face="Courier New"> (define normalized-arity (normalize-arity arity))</font></div><div><font face="Courier New"> (flat-named-contract</font></div><div><font face="Courier New"> `(procedure-has-arity/c ,normalized-arity)</font></div><div><font face="Courier New"> (λ (f)</font></div><div><font face="Courier New"> (and (procedure? f)</font></div><div><font face="Courier New"> (arity=? (procedure-arity f) normalized-arity)))))</font></div></div><br><div><div>On Jun 29, 2014, at 8:00 AM, Roman Klochkov <<a href="//e.mail.ru/compose/?mailto=mailto%3akalimehtar@mail.ru" target="_blank">kalimehtar@mail.ru</a>> wrote:</div><br><blockquote type="cite">
<div><p>How to make a contract, that accepts <br>(-> input-port? any/c any)<br>(-> input-port? any/c any/c any)<br>(-> input-port? any/c any/c any/c any)<br>...<br>and<br>(->* (input-port? any/c) #:rest list? any)</p><p><br>So theare should be at least two args and first arg should be input-port.<br><br>-- <br>Roman Klochkov</p></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br></blockquote></div><br>
</div>
<base href="https://e.mail.ru/" target="_self">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>