<HTML><BODY>> Why does list? allow a vector in the following contract? <br><br>Contract in `provide' is used only when you `require' your module from other. If you want always test it, use define/contract<br><br>> Also, how do I indicate an optional (in this case keyword) argument?<br><br><a href="http://docs.racket-lang.org/reference/function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29">http://docs.racket-lang.org/reference/function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29</a><br><br>(->* (list? exact-nonnegative-integer?) (#:splice boolean?) any)<br><br><br>Tue, 19 Aug 2014 22:44:57 -0700 от Kevin Forchione <lysseus@gmail.com>:<br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
<div id="">
<div class="js-helper js-readmsg-msg">
<style type="text/css"></style>
<div>
<base target="_self" href="https://e.mail.ru/">
<div id="style_14085143380000000112_BODY">Hi guys,<br>
In an attempt to tighten up my code I started using the raise-xxxx-error feature and then began looking at contracts. I like the concept and think it would lead to cleaner looking code But I have two questions:<br>
<br>
Why does list? allow a vector in the following contract? Also, how do I indicate an optional (in this case keyword) argument? <br>
<br>
(I’m assuming I’d have to define a contract to handle the valid exact-nonnegative-integer/range for the index, unless there is one already defined. I’ll have a go at that later. )<br>
<br>
#lang racket<br>
<br>
(provide (contract-out <br>
(insert-at (list? exact-nonnegative-integer? any/c . -> . any))))<br>
<br>
(define (insert-at lst index val #:splice (splice #f))<br>
#;(unless (list? lst)<br>
(raise-argument-error 'insert-at "list?" lst))<br>
#;(uqnless (exact-nonnegative-integer? index)<br>
(raise-argument-error 'insert-at "exact-nonnegative-integer?" index))<br>
#;(unless (<= index (length lst))<br>
(raise-range-error 'insert-at "list" "" index lst 0 (length lst)))<br>
#;(unless (boolean? splice)<br>
(raise-argument-error 'insert-at "boolean?" splice))<br>
<br>
(define-values (head tail) (split-at lst index))<br>
(append head<br>
(cond<br>
[(and splice (cons? val)) val]<br>
[else (list val)])<br>
tail))<br>
<br>
>(insert-at #(a b) 0 ‘c)<br>
'(c . #(a b))<br>
<br>
Thanks!<br>
<br>
-Kevin<br>
<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>
</div>
<base target="_self" href="https://e.mail.ru/">
</div>
</div>
</div>
</blockquote>
<br>
<br>-- <br>Roman Klochkov<br></BODY></HTML>