I had always assumed that case-lambda just checked alternatives in order until one matched - like a cond. But, that was just an assumption on my part and subject to being absolutely wrong. [But, if it is correct I would expect case-> to allow overlapping contracts.]<br>
<br>Another thing I just noticed is that the documentation says that case-lambda is provided by scheme/base and scheme - and doesn't mention racket/base or racket. To me that implies that isn't available in the racket language, but I'm sure it is. Is that a documentation error? But lambda says the same thing, so I guess it is a misinterpretation on my part of what scheme versus racket means in the docs.<br>
<br>Doug<br><br><div class="gmail_quote">On Mon, Oct 25, 2010 at 8:46 AM, 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;">
Thanks, that's a great example. The idea (at least from the contract's<br>
point of view) is that there are two different functions with one name<br>
that have two different arities, I think.<br>
<br>
So maybe the right way to bring back case-> is that contracts that<br>
match functions should come with some way to find out what arities<br>
they can match (this is kind of there implicitly now, but probably<br>
needs to be explicit) and then say that either there is no overlap or<br>
there is an ordering so that, given a function with some specific<br>
arity (arities) it gets slotted into particular parts of the contracts<br>
inside the case->. (thinking a little bit, I guess that we'd have to<br>
say that there should not be any overlap or else we'd have to kind of<br>
mix and match parts of contracts to parts of functions that seems<br>
pretty complex (if that's too opaque I can give an example to explain<br>
what I meant))<br>
<br>
Robby<br>
<br>
On Mon, Oct 25, 2010 at 9:06 AM, Doug Williams<br>
<div><div></div><div class="h5"><<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
> 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<br>
> can rewrite them using optional parameters.<br>
><br>
> But, in the random distribution functions it is the first argument that is<br>
> optional and that won't work. So, for example the flat (i.e., uniform)<br>
> 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<br>
> system. [I think I would have to move the b > a constraint into the code<br>
> itself in the current contract system. Or, change the argument order and<br>
> break backward compatibility.]<br>
><br>
> Doug<br>
><br>
><br>
> On Sun, Oct 24, 2010 at 6:23 PM, Robby Findler <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>><br>
> wrote:<br>
>><br>
>> 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>
>> <<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
>> > 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<br>
>> > contract)).<br>
>> > All of that seems to mean that I can't just add #:flat? #t - I get a<br>
>> > message<br>
>> > that vector-of doesn't accept keyword arguments. And, the case-><br>
>> > 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<br>
>> > some<br>
>> > conversion work to do.<br>
>> ><br>
>> > On the case-> problem, it seems it no longer supports anything but ->.<br>
>> > 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>><br>
>> > 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<br>
>> >> > 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<br>
>> >> > often<br>
>> >> > still work (in the sense of not getting any error or crashing), but<br>
>> >> > 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.<br>
>> >> > 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>
>> > _________________________________________________<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>
><br>
><br>
</div></div></blockquote></div><br>