<HTML><BODY>Thank you very much!<br>This is it.<br><br><br>Sun, 29 Jun 2014 20:39:33 -0500 от Robby Findler <robby@eecs.northwestern.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_14040923770000000974_BODY">Yes, I believe this is what you want:<br>
<br>
#lang racket<br>
<br>
(define (chaperone-f f)<br>
(chaperone-procedure<br>
f<br>
(λ (fst . more)<br>
(printf "fst arg: ~s\n" fst)<br>
(apply values fst more))))<br>
<br>
((chaperone-f (λ (x y) x)) 1 2)<br>
((chaperone-f (λ (x y z) x)) 1 2 3)<br>
((chaperone-f (λ (x y z w) x)) 1 2 3 4)<br>
<br>
On Sun, Jun 29, 2014 at 8:10 PM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
> I reformulate my problem:<br>
> I need to make a chaperone, that checks only type of first arg. Is it<br>
> possible?<br>
><br>
> If yes, I'll sumply make something like<br>
> (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"<br>
> <<a href="/compose?To=alexander@knauth.org">alexander@knauth.org</a>>:<br>
><br>
> You can use or/c to do this, as long as you guard them like this so that no<br>
> more than one contract matches at a time:<br>
> (or/c<br>
> (and/c (procedure-has-arity/c 2) (-> input-port? any/c any))<br>
> (and/c (procedure-has-arity/c 3) (-> input-port? any/c any/c any))<br>
> (and/c (procedure-has-arity/c 4) (-> input-port? any/c any/c any/c any))<br>
> (->* (input-port? any/c) #:rest list? any)<br>
> )<br>
><br>
> Or, you could use if/c from unstable/contract, or define a cond/c macro like<br>
> this:<br>
> (require unstable/contract)<br>
> (define-syntax cond/c<br>
> (syntax-rules (else)<br>
> [(cond/c) none/c]<br>
> [(cond/c [else else-c])<br>
> else-c]<br>
> [(cond/c [pred then-c] clause ...)<br>
> (if/c pred<br>
> then-c<br>
> (cond/c clause ...))]))<br>
><br>
> (cond/c [(procedure-has-arity/c 2) (-> input-port? any/c any)]<br>
> [(procedure-has-arity/c 3) (-> input-port? any/c any/c any)]<br>
> [(procedure-has-arity/c 4) (-> input-port? any/c any/c any/c any)]<br>
> [else (->* (input-port? any/c) #:rest list? any)])<br>
><br>
> By the way it has to be procedure-has-arity/c, not<br>
> procedure-includes-arity/c:<br>
> (define (procedure-has-arity/c arity)<br>
> (define normalized-arity (normalize-arity arity))<br>
> (flat-named-contract<br>
> `(procedure-has-arity/c ,normalized-arity)<br>
> (λ (f)<br>
> (and (procedure? f)<br>
> (arity=? (procedure-arity f) normalized-arity)))))<br>
><br>
> On Jun 29, 2014, at 8:00 AM, Roman Klochkov <<a href="/compose?To=kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>
><br>
> 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)<br>
><br>
><br>
> So theare should be at least two args and first arg should be input-port.<br>
><br>
> --<br>
> Roman Klochkov<br>
><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>
> --<br>
> Roman Klochkov<br>
><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>
</div>
<base href="https://e.mail.ru/" target="_self">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>