<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><base></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>You can use `module+` to automatically create a submodule that invokes your contracts, while the main module ignores them.</div><div><br></div><div>Then if you want speed, you can import your module as </div><div><br></div><div>(require module-name) </div><div><br></div><div>or if you want safety, you can import as</div><div><br></div><div>(require (submod module-name safe))</div><div><br></div><div>Here's how I did it:</div><div><br></div><div><a href="https://github.com/mbutterick/txexpr/blob/master/main.rkt">https://github.com/mbutterick/txexpr/blob/master/main.rkt</a></div><div><br></div><div><br></div><div><br></div><br><div><div>On Jun 3, 2014, at 12:28 PM, Roman Klochkov <<a href="mailto:kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: TriplicateT3PolyTall; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On the other side of the question:<br>one may simply make something like<br><br>(module lib/unsafe racket/base<br>   (provide foo bar baz)<br>   ...)<br><br>(module lib racket/base<br>  (require lib/unsafe)<br>  (provide/contract<span class="Apple-converted-space"> </span><br>     (foo (-> integer? any))<br>     (bar (-> list? list?)))<br><br>(module lib/debug racket/base<br>  (require lib/unsafe lib/checks)<br>  (provide/contract<span class="Apple-converted-space"> </span><br>     (foo (->i [x integer?] [result (complicated-check? result]))<br>     (bar (-> sorted-integer-list? sorted-integer-list?)))<br><br>To debug simply use */debug, and for max speed */unsafe... I need to think about it.<br><br><br><br>Tue, 3 Jun 2014 13:58:59 -0400 от Jay McCarthy <<a href="mailto:jay.mccarthy@gmail.com">jay.mccarthy@gmail.com</a>>:<br><blockquote style="margin: 10px; padding: 0px 0px 0px 10px; border-left-color: rgb(8, 87, 166); border-left-width: 1px; border-left-style: solid;"><div class="js-helper js-readmsg-msg"><base href="https://e.mail.ru/" target="_self"><div id="style_14018183410000000427_BODY"><div>Roman,</div><div><br></div><div>This approach is unlikely to work out due to separate compilation. Module A can't really affect how module B gets compiled. Your contract-mode appears to be trying to do such a thing.</div><div><br></div><div>So it is not clear where the decision on compile mode is made. If it is inside a module, then why not turn them off to remove contracts that enforce things like security?</div><div><br></div><div>Something like this seems to be "outside" of the language. I have thought that the right place would be inside the compiler or something like the demodularizer. Further, I imagine a general mechanism that turns</div><div><br></div><div>(if p e (error ...))</div><div><br></div><div>into just</div><div><br></div><div>e</div><div><br></div><div>Instead of baked-in cooperation with and knowledge of contracts.</div><div><br></div><div>Jay<br><br>Sent from my iPhone</div><div><br>On Jun 3, 2014, at 1:16 PM, Roman Klochkov <<a href="x-msg://e.mail.ru/compose/?mailto=mailto%3akalimehtar@mail.ru" target="_blank">kalimehtar@mail.ru</a>> wrote:<br><br></div><blockquote type="cite">Will you accept patch for this, if I'll write it?<br><br>(contract-out ...) will have (id debug-contract-expr production-contract-expr) instead of (id contract-expr) in syntax<br>There will be global phase-1 variable<span class="Apple-converted-space"> </span><br>contract-mode : (or/c 'nothing 'production 'pre 'pre-and-past 'all) = 'all<br><br>nothing -- no checks<br>production -- use production contract if present, otherwise check only pre-condiction<br>pre -- check only pre-condiction<br>pre-and-post -- check pre and post conditions<br>all -- current behavior<br><br><br><br><br>Tue, 3 Jun 2014 12:47:18 -0400 от Matthias Felleisen <<a href="x-msg://e.mail.ru/compose/?mailto=mailto%3amatthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>>:<br><blockquote style="margin: 10px; padding: 0px 0px 0px 10px; border-left-color: rgb(8, 87, 166); border-left-width: 1px; border-left-style: solid;"><br>Your mail calls for a philosophical answer. If this were Eiffel, you would be correct.<span class="Apple-converted-space"> </span><br><br>But Racket is not Eiffel:<span class="Apple-converted-space"> </span><br> -- we are not a tools company that sells a language<span class="Apple-converted-space"> </span><br> -- we spent our own time on a maintenance effort that goes above and beyond our jobs<span class="Apple-converted-space"> </span><br> -- and we don't provide a standard language (meant to make developers happy and its creators famous and wealthy).<span class="Apple-converted-space"> </span><br><br>Racket is a programming language programming language [not a typo]. We wish to go beyond conventional features. When it comes to contracts, this means we wish to provide (1) higher-order contracts so that we cover the full spectrum of linguistic features and (2) a programmable toolbox so that programmers can create their own favorite idioms -- above and beyond the stuff available in standard languages.<span class="Apple-converted-space"> </span><br><br>We fully understand that expanding the horizons of the language puts some burden on programmers. Every programmer may have to develop his own techniques and tools and idioms for our new features. We balance this burden with a catalog-driven on-line library, where programmers can register little more than a github URL to share such libraries.<span class="Apple-converted-space"> </span><br><br>With apologies for the extra burden and the non-technical answer -- Matthias<br><br><br><br><br><br><br><br>On Jun 3, 2014, at 12:24 PM, Roman Klochkov <<a target="_blank"></a><a href="mailto:kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br><br>> There should be _standard_ check-modes. With global variable (or better compile-mode).<br>><span class="Apple-converted-space"> </span><br>> Because, I can in my own libraries make this 4 or even more modes. But I use 3d-party or standard library. And I cannot rewrite them all to my 4 modes.<span class="Apple-converted-space"> </span><br>> Even if another developer will use the same idea, he or she will have own modes and own variable to set them.<br>><span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> Tue, 3 Jun 2014 07:47:37 -0400 от Matthias Felleisen <<a target="_blank"></a><a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>>:<br>><span class="Apple-converted-space"> </span><br>> You can program these scenarios with option contracts; see comparison in paper. Perhaps it's time to write this up as a chapter for the Guide.<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> On Jun 3, 2014, at 12:38 AM, Daniel Prager wrote:<br>><span class="Apple-converted-space"> </span><br>>> > I propose something like two contracts: for debug and production modes.<br>>><span class="Apple-converted-space"> </span><br>>> Eiffel compilers implement a sliding scale of contract-checking, something like:<br>>> • Check nothing [naive]<br>>> • Check pre-conditions only [good for production - quick]<br>>> • Check pre- and post-conditions only [can be slow]<br>>> • Check pre- and post-conditions and invariants [van be very slow]<br>>> [Loop and ad hoc assertions would have been in there too.]<br>>><span class="Apple-converted-space"> </span><br>>> Post-conditions and invariants can be *very* expensive to check, but are great when debugging.<br>>><span class="Apple-converted-space"> </span><br>>> Pre-condition checking is typically cheap, and quickly tells you when trusted code is being called with bad arguments.<br>>><span class="Apple-converted-space"> </span><br>>> Recommeneded development practice was to start with all contracts checked, and as one's code iterated towards trustworthiness turn down the checking-level (but leave pre-conduitions on) and enjoy the huge speed boost.<br>>><span class="Apple-converted-space"> </span><br>>> There's value in being able to control checking on a per module basis, essentially doing deep checks on newer / less-tested / less-trusted parts of the system.<br>>><span class="Apple-converted-space"> </span><br>>> How does the picture change with higher-order contracts and checking at module boundaries?<br>>><span class="Apple-converted-space"> </span><br>>> Dan<br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> On Tue, Jun 3, 2014 at 6:20 AM, Roman Klochkov <<a target="_blank"></a><a href="mailto:kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>>> The problem is that, when debbugging, contract should be precise. For example, insert-in-sorted-queue may check that queue is orted before and after the function.<span class="Apple-converted-space"> </span><br>>> But inserting the element is O(log n) and testing will be O(n).<br>>><span class="Apple-converted-space"> </span><br>>> option contracts -- 1) unstable 2) should be turned off and on individually.<br>>><span class="Apple-converted-space"> </span><br>>> For quick hack, I'll simply redefine contract-out and recompile all. But I propose something like two contracts: for debug and production modes.<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> Mon, 2 Jun 2014 15:49:05 -0400 от Matthias Felleisen <<a target="_blank"></a><a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>>:<br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> On Jun 2, 2014, at 3:42 PM, Roman Klochkov <<a target="_blank"></a><a href="mailto:kalimehtar@mail.ru">kalimehtar@mail.ru</a>> wrote:<br>>><span class="Apple-converted-space"> </span><br>>> > Is there a way to disable all contract checks?<span class="Apple-converted-space"> </span><br>>> ><span class="Apple-converted-space"> </span><br>>> > Suppose, I debugged my program and sure that it is reliable. I disable debugging, but as I understand, contracts are still checked in every function.<br>>> > But I want to maximize the performance of my program. Is there a way to do that or I have to manually hack racket/contract/base to do that?<br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> No.<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> ;; ---<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> Programmers who disable assertion checking as they are deploying software are like people who wear life vests on land when they learn about the theory of sailing and take them off as soon as they board the boat for practical exercises on the water. -- somebody famous<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> ;; ---<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> You will need to define a version of provide and/or contract-out that throws away contracts based on a switch.<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> Or you check out option contracts and use those.<span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> -- Matthias<br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> --<span class="Apple-converted-space"> </span><br>>> Roman Klochkov<br>>><span class="Apple-converted-space"> </span><br>>> ____________________<br>>> Racket Users list:<br>>><span class="Apple-converted-space"> </span><a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>><span class="Apple-converted-space"> </span><br>>> --<span class="Apple-converted-space"> </span><br>>> Daniel Prager<br>>> Agile/Lean Coaching, Software Development and Leadership<br>>> Startup:<span class="Apple-converted-space"> </span><a href="http://www.youpatch.com/" target="_blank">www.youpatch.com</a><br>>> Twitter: @agilejitsu<span class="Apple-converted-space"> </span><br>>> Blog:<span class="Apple-converted-space"> </span><a href="http://agile-jitsu.blogspot.com/" target="_blank">agile-jitsu.blogspot.com</a><br>><span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> --<span class="Apple-converted-space"> </span><br>> Roman Klochkov<br><br></blockquote><br><br>--<span class="Apple-converted-space"> </span><br>Roman Klochkov<br></blockquote><blockquote type="cite"><span>____________________</span><br><span> Racket Users list:</span><br><span> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a></span><br></blockquote></div><base href="https://e.mail.ru/" target="_self"></div></blockquote><br><br>--<span class="Apple-converted-space"> </span><br>Roman Klochkov<br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></div></blockquote></div><br></body></html>