On Tuesday, May 19, 2015 at 12:23:34 AM UTC-4, Alexis King wrote:
> I've recently wanted a contract that lets me check the last element of a 
> (potentially improper) list, ignoring the other elements. To do this in a 
> general sense, I came up with this.
> 
> (define (listof* init/c last/c)
>   (flat-named-contract
>    `(listof* ,(contract-name init/c) ,(contract-name last/c))
>    (flat-rec-contract listof* last/c (cons/c init/c listof*))))
> 
> That definition can then be used like this.
> 
> (define/contract num-tail
>   (listof* any/c number?)
>   '(a b c . 4))
> 
> The use-case I've found most helpful, though, is combining it with listof 
> contracts to check sequences within lists or at the end of the lists.
> 
> (define/contract num-tail-proper
>   (listof* any/c (list/c number?))
>   '(a b c 4))
> 
> This works, but it only works with flat contracts. Would it be possible to 
> generalize this to work with all contracts? Also, would this sort of 
> combinator make sense in the standard library? The name I've used probably 
> wouldn't be usable (since it could be confused with list*of), but I think the 
> functionality is helpful.

I think what you are aiming for can be done using chaperone contracts 
(Documentation link: http://goo.gl/y7W6Nu). Does the attached file seem to 
demonstrate what you are looking for?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: chaperone-listof-c.rkt
Description: Binary data

Reply via email to