Here is one example.<br><br> (make-discrete-histogram<br> (case-> (->r ((n1 integer?)<br> (n2 (and/c integer?<br> (>=/c n1)))<br> (dynamic? boolean?))<br> discrete-histogram?)<br>
(->r ((n1 integer?)<br> (n2 (and/c integer?<br> (>=/c n1))))<br> discrete-histogram?)<br> (-> discrete-histogram?)))<br><br>This code predates optional and keyword parameters. In cases like this, I can rewrite them using optional parameters.<br>
<br>But, in the random distribution functions it is the first argument that is optional and that won't work. So, for example the flat (i.e., uniform) distribution includes a contract:<br><br> (case-> (->r ((r random-source?)<br>
(a real?)<br> (b (>/c a)))<br> real?)<br> (->r ((a real?)<br> (b (>/c a)))<br> real?)))<br><br>I'm not sure that one can be easily rewritten in the current contract system. [I think I would have to move the b > a constraint into the code itself in the current contract system. Or, change the argument order and break backward compatibility.]<br>
<br>Doug<br><br><br><div class="gmail_quote">On Sun, Oct 24, 2010 at 6:23 PM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The new case-> only supports simple contracts, that's right. If you<br>
have more complex ones that it would be helpful to support (and can<br>
share them), that would help us guide our efforts.<br>
<br>
Thanks,<br>
Robby<br>
<br>
On Sun, Oct 24, 2010 at 7:04 PM, Doug Williams<br>
<div class="im"><<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
</div><div><div></div><div class="h5">> The main problem I'm having is that the code has been around awhile and<br>
> hasn't been fully converted to Racket - in particular it uses the scheme<br>
> language (instead of the racket language) and uses (require (lib contract)).<br>
> All of that seems to mean that I can't just add #:flat? #t - I get a message<br>
> that vector-of doesn't accept keyword arguments. And, the case-> contracts<br>
> use ->r, which apparently isn't supported anymore. All that means that I<br>
> can't just switch to the racket language and new contracts. So, I have some<br>
> conversion work to do.<br>
><br>
> On the case-> problem, it seems it no longer supports anything but ->. Is<br>
> there something I am missing there?<br>
><br>
> Doug<br>
><br>
> On Sun, Oct 24, 2010 at 8:53 AM, Matthew Flatt <<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>> wrote:<br>
>><br>
>> At Fri, 22 Oct 2010 21:31:43 -0600, Doug Williams wrote:<br>
>> > Matthew, would it make more sense to have unsafe-vector-ref (and related<br>
>> > functions) be the more general function and unsafe-vector*-ref be the<br>
>> > one<br>
>> > that doesn't work on chaperoned vectors? That is just swap the<br>
>> > definitions.<br>
>> > That way user code that is already using unsafe-vector-ref (etc) will<br>
>> > continue to work.<br>
>> ><br>
>> > As it stands, existing code that has unsafe-vector-ref (etc) will often<br>
>> > still work (in the sense of not getting any error or crashing), but just<br>
>> > gives the wrong results. For example, if you run science-test.ss from<br>
>> > the<br>
>> > examples directory in the science collection, there are no errors. But,<br>
>> > some<br>
>> > of the answers are wrong - for example the very first one, the gamma<br>
>> > function. [In other cases, like the FFT routines, there are either<br>
>> > run-time<br>
>> > errors or crashes.]<br>
>> ><br>
>> > Anyway, if it isn't too late, I think swapping the definitions would<br>
>> > make<br>
>> > more sense and be safer.<br>
>><br>
>> I've gone back and forth. I agree that it would be safer, but<br>
>> `vector-ref' is safer still, and I think of the job of `unsafe-X' as<br>
>> providing the lowest possible overhead over `X'. It seems nicer to me<br>
>> to have `*' mean "somewhere in between" rather than "even faster". Then<br>
>> again, it seems bad that `vector?' (plus index bounds) isn't enough to<br>
>> guard `unsafe-vector-ref'.<br>
>><br>
>> Overall, at this point in the release cycle, I'm inclined to leave<br>
>> things where they are (i.e., it may be too late). But let's hear more<br>
>> opinions from those who use `unsafe-vector-ref' and<br>
>> unsafe-vector*-ref'.<br>
>><br>
><br>
><br>
</div></div><div><div></div><div class="h5">> _________________________________________________<br>
> For list-related administrative tasks:<br>
> <a href="http://lists.racket-lang.org/listinfo/dev" target="_blank">http://lists.racket-lang.org/listinfo/dev</a><br>
><br>
</div></div></blockquote></div><br>