[racket] Contracts and submodules
Not to flog this, but:
Lately I've been trying to be a good little doobie and use `(provide
(contract-out))` instead of `define/contract`. Although it's more
typing/clutter, grumble grumble, I've been getting used to it.
Unfortunately I discovered one gotcha: Using (module+ test <rackunit
tests>) means that the test bypasses the contract -- because it's a
submodule, and the contract is on the module boundary. So my unit
tests weren't exercising and validating the contract. I missed a buggy
contract this way.
In hindsight this is all perfectly obvious. Just not from the guide.
To be fair using submodules for tests is a relatively recent practice
in Racket. But I wanted to point out the interaction in case it helps
anyone else who is trying to use module contracts and do unit tests
following the curent examples.
One way to avoid this problem is instead of module+ use module*:
(module* test racket ;; To test module-boundary contracts, must use
;; module* and (require (submod "..")).
(require (submod ".."))
... check check check ...
)
Of course this adds even more "clutter", but it works.
On Thu, Dec 27, 2012 at 3:31 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
> I have added a note on this issue to the Style issue; see section 3.6. Strictly speaking, this prose probably belongs into the Contract guide. -- Matthias
>
>
>
> On Nov 30, 2012, at 5:17 PM, Ryan Culpepper wrote:
>
>> You can have mutually recursive functions with define/contract, but you can't with submodules.
>>
>> Ryan
>>
>> On 11/30/2012 05:04 PM, Ray Racine wrote:
>>> Why not make this explicit by deprecating define/contract and support
>>> this use case with a submodule. They lightweight enough and makes
>>> boundary demarcations consistent, explicit and simple. Module -> boundary.
>>>
>>> On Nov 30, 2012 12:05 PM, "Matthias Felleisen" <matthias at ccs.neu.edu
>>> <mailto:matthias at ccs.neu.edu>> wrote:
>>>
>>>
>>> On Nov 30, 2012, at 10:15 AM, Greg Hendershott wrote:
>>>
>>> >> This is a complete misunderstanding.
>>> >
>>> > Sometimes I feel like a kid in the room while the adults are talking.
>>> > When it comes to contracts, I have to stipulate that most of you are
>>> > smarter than me and have thought about this longer than me.
>>>
>>>
>>> Apologies. My opening wasn't meant to say "I am smarter" but I wanted
>>> to send a strong message about define/contract. It really introduces a
>>> boundary and in some strange sense your (possibly misleading)
>>> microbenchmark
>>> exposes this constraint too.
>>>
>>>
>>>
>>> ____________________
>>> Racket Users list:
>>> http://lists.racket-lang.org/users
>>>
>>>
>>>
>>> ____________________
>>> Racket Users list:
>>> http://lists.racket-lang.org/users
>>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users