[racket] procedure contract for "at least N arguments, possibly more"

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Jun 8 23:15:16 EDT 2012

It is kind of like you want a dependent contract: once the first
function is called then it's range contract is forever fixed to some
specific number of values and after that the domain of P2 is also
fixed to some specific number of values.

You can drop down to the low-level and write such a contract, I
believe, but the combinators can't express it, I'm sorry to say.


On Fri, Jun 8, 2012 at 8:57 PM, Neil Van Dyke <neil at neilvandyke.org> wrote:
> Robby Findler wrote at 06/08/2012 09:31 PM:
>> To get a little more context: what happens if P1 returns different
>> numbers of values each time it is called?
> That would be a programming error by the user of this library, and I'm fine
> with them getting a non-contracts runtime error.
> I think my root problem here is that I'm trying to make the contract stuff
> let me not actually use the contract stuff much.  I'm doing this because my
> documentation thing encourages the use of contracts.
> Anyway, a more concrete example of why I wanted this is below.  I thought
> I'd be cute, and have "progedit-file" provide a convenient functional way
> for people to communicate arbitrary info like syntax objects and hashes from
> P1 to P2.
> (progedit-file actual-path
>               #:read
>               (lambda (in) ;; This is P1.
>                 (syntax-parse (read-syntax 'my-source in)
>                   ((A B C) (values #'A #'B #'C))))
>               #:write
>               (lambda (in out a-stx b-stx c-stx) ;; This is P2.
>                 (progedit in
>                           out
>                           #:inserts  `(((after  ,b-stx) " After")
>                                        ((before ,b-stx) "Before ")))
>                           #:replaces `((,b-stx "Replaced")))))
>> Also, perhaps not the best thing (pending the answer above), you can
>> write a predicate contract that gets the procedure-arity result and do
>> what you want with it. That doesn't work well if you want to actually
>> put contracts on the two arguments, tho.
> I think I'll just use "procedure?" in the contract.  Or get rid of the cute
> passing of info.
> Thanks,
> Neil V.
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

Posted on the users mailing list.