Would an append/c combinator be a good generalization of this?

I’ve already made an append/c combinator that works with just flat-contracts, 
but is there a good way to make it work for chaperone contracts?

https://github.com/AlexKnauth/match-string/blob/master/match-string/main.rkt#L205
http://pkg-build.racket-lang.org/doc/match-string/index.html#%28def._%28%28lib._match-string%2Fmain..rkt%29._append%2Fc%29%29

Also if any of you happen to look at this and have any suggestions, that would 
be great.

On May 20, 2015, at 8:43 PM, Philip Blair <peblair...@gmail.com> wrote:

> 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.
> <chaperone-listof-c.rkt>

-- 
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.

Reply via email to