Clojure JIRAhttp://dev.clojure.org/jira/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+CCONTRACTS+AND+resolution+%3D+Unresolved+ORDER+BY+priority+DESC
An XML representation of a search requesten-us4.464925-07-2011[CCONTRACTS-2] Does clojurescript support work for core.contracts?http://dev.clojure.org/jira/browse/CCONTRACTS-2
core.contracts<p>I have a pedestal app I am working on. I have made some really helpful (at least to me) use of core.contracts in testing my clojure/clojurescript shared code (in clojure) using test.generative. When I open my code in the browser though and try to bring a namespace that makes use of core.contracts into clojurescript, I get the following error. None of the constraints I wrote actually make use of any native java types (at least I don't think). I am mostly just checking that the values of things align with what I expect in the inputs and outputs.</p>
<p>In my behavior.clj I have</p>
<p>(ns ^:shared com.samedhi.contracts.app.behavior<br/>
(:require <span class="error">&#91;clojure.string :as string&#93;</span><br/>
<span class="error">&#91;io.pedestal.app.messages :as msg&#93;</span><br/>
<span class="error">&#91;clojure.zip :as z&#93;</span>)<br/>
(:use [clojure.core.contracts :only <span class="error">&#91;contract with-constraints&#93;</span>]<br/>
[clojure.core.contracts.constraints :only <span class="error">&#91;defconstrainedfn&#93;</span>]<br/>
[clojure.test :only <span class="error">&#91;is&#93;</span>]))</p>
<p>which compiles into cljs as <br/>
...<br/>
goog.require('clojure.core.contracts.constraints');<br/>
goog.require('com.samedhi.quizry.app.quiz');<br/>
goog.require('clojure.core.contracts');<br/>
goog.require('clojure.test');<br/>
...</p>
<p>which throws a javascript exception at goog.require('clojure.core.contracts.constraints') when I look in the data-ui view, saying:</p>
<p>errorMessage: "goog.require could not find: clojure.core.contracts.constraints"<br/>
name: "clojure.core.contracts.constraints"</p>
<p>Is there some sort of special way I need to import things within clojurescript to use core.contracts?</p>
<p>BTW, I really appreciate core contracts, it is really neato. Thanks for you work.</p>ClojurescriptCCONTRACTS-2Does clojurescript support work for core.contracts?EnhancementMajorOpenUnresolvedFogusStephen CagleFri, 6 Sep 2013 17:55:41 -0500Fri, 6 Sep 2013 17:55:41 -050000Global Rank[CCONTRACTS-3] & for additional arguments does not seem to work when declaring a contracthttp://dev.clojure.org/jira/browse/CCONTRACTS-3
core.contracts<p>user&gt; (use '[clojure.core.contracts :only <span class="error">&#91;contract&#93;</span>])<br/>
nil<br/>
user&gt; (contract<br/>
silly<br/>
"Silly reporting for duty sir!"<br/>
[<span class="error">&#91;a &amp; b :as c&#93;</span>]<br/>
[])<br/>
CompilerException java.lang.RuntimeException: Unable to resolve symbol: &amp; in this context, compiling:(NO_SOURCE_PATH:1:1)</p>
<p>the &amp; in "a &amp; b" is unresolved.</p>CCONTRACTS-3& for additional arguments does not seem to work when declaring a contractDefectMajorOpenUnresolvedFogusStephen CagleSat, 7 Sep 2013 22:29:48 -0500Sat, 7 Sep 2013 22:29:48 -050000Global Rank[CCONTRACTS-4] provide macro fails for multiple constraintshttp://dev.clojure.org/jira/browse/CCONTRACTS-4
core.contracts<p>The following code shows 2 ways for defining a function with constraints.</p>
<p>=&gt; it works as expected using the with-constraints macro<br/>
=&gt; it fails on the second contract using the provide macro</p>
<p>(require '<span class="error">&#91;clojure.core.contracts :as ccc&#93;</span>)</p>
<p>;; because the provide macro alters the var-root, let's keep two separate identical functions for the test.</p>
<p>(defn qux <span class="error">&#91;x&#93;</span> x)<br/>
(defn bar <span class="error">&#91;x&#93;</span> x)</p>
<p>;; define 2 contracts<br/>
(def c1 (ccc/contract c1-cx "should be odd"<br/>
<span class="error">&#91;x&#93;</span> <br/>
<span class="error">&#91;(odd? x)&#93;</span>))</p>
<p>(def c2 (ccc/contract c2-cx "should have one digit" <br/>
<span class="error">&#91;x&#93;</span><br/>
<span class="error">&#91;(= 1 (count (str x)))&#93;</span>))</p>
<p>;; using the provide macro =&gt; c1 is asserted, c2 never. When we swap around c2 c1, then c2 is asserted, c1 never<br/>
(ccc/provide <span class="error">&#91;qux &quot;qux&quot; c1 c2&#93;</span>)</p>
<p>;; on the other hand, using with-constraints works as expected.<br/>
(def qux-g<br/>
(ccc/with-constraints bar c1 c2))</p>
<p>(qux 2) ;; expected assertion "should be odd"<br/>
(qux 3) ;; expected 3 <br/>
(qux 23) ;; expected assertion "only one digit", but we get 23</p>
<p>(qux-g 2) ;; should be odd<br/>
(qux-g 3) ;; OK<br/>
(qux-g 23) ;; should be positive</p>clojure 1.5
<br/>
core.contracts 0.5CCONTRACTS-4provide macro fails for multiple constraintsDefectMajorOpenUnresolvedFogusjoerupenTue, 28 Jan 2014 14:04:46 -0600Tue, 28 Jan 2014 14:04:46 -060000Global Rank[CCONTRACTS-5] Fix links in and display of documentationhttp://dev.clojure.org/jira/browse/CCONTRACTS-5
core.contracts<p>There is a number of problems with the way the documentation is made available and interlinked:</p>
<ul>
<li>Currently most people likely arrive to <a href="https://github.com/clojure/core.contracts">https://github.com/clojure/core.contracts</a> and read the README - but it does not point to the docs in <tt>./docs/</tt> =&gt; add link to it there</li>
<li>It is not clear how the docs are expected to be browsed; I suppose that the .org<br/>
files should be exported to <tt>./docs/wiki/*.markdown</tt> yet not all of them are. I also<br/>
suppose that the exported markdown files should be available under <a href="https://github.com/clojure/core.contracts/wiki">https://github.com/clojure/core.contracts/wiki</a>, i.e. pushed to git@github.com:clojure/core.contracts.wiki.git</li>
<li>Some of the problems:</li>
<li>the link "return to documentation" on e.g. "with-constraints" should point to /clojure/core.contracts/wiki, not /clojure/core.contracts/docs.html</li>
<li>if wiki is really exported, the main page should mention it is immutable</li>
<li>links on the home page <b>had</b> one more 'wiki' in them (fixed manually in the wiki - will be overriden by the next export)</li>
<li>some links are broken, f.ex. <span class="error">&#91;defconstrainedfn&#93;</span>(/clojure/core.contracts/wiki/defconstrainedfn) on f.ex. <tt>contract</tt>; <span class="error">&#91;with-constraints&#93;</span>(/clojure/core.contracts/with-constraints/) (missing /wiki/), <span class="error">&#91;defcontract&#93;</span>(/clojure/core.contracts/wiki/defcontract/)</li>
</ul>
<p>It would certainly help the project if the documentation was easier to access and browse <img class="emoticon" src="http://dev.clojure.org/jira/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"/></p>
<p>Thank you</p>CCONTRACTS-5Fix links in and display of documentationTaskMajorOpenUnresolvedFogusJakub HolydocumentationWed, 30 Apr 2014 06:37:14 -0500Wed, 30 Apr 2014 06:37:14 -050000Global Rank[CCONTRACTS-6] Add/improve docs of contract, clojure.core.contracts, etc.http://dev.clojure.org/jira/browse/CCONTRACTS-6
core.contracts<p>Even though <tt>contract</tt> is a key thing in the library, it lacks a docstring.<br/>
The docstring of the ns could also have a few words pointing to the main functions<br/>
and how to use them.</p>
<h3><a name="contract"></a>contract</h3>
<p>For contract, st. like would be nice (excuse my poor understanding of the lib):</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Define a named and documented contract.
constraints =&gt; signature-constraint*
signature-constraint =&gt; argument-vector constraint-vector
constraint-vector =&gt; functions and expressions [=&gt; functions and expressions]
The functions are applied to the arguments, an expressions is executed as-is.
Constraint following `=&gt;` are post-conditions and may use `%` to refer to the <span class="code-keyword">return</span> value.
Ex.:
(contract doubler
<span class="code-quote">"ensures doubling (sometimes)"</span>
[x] [number? =&gt; integer?]
[x y] [(every? number? [x y])
=&gt;
integer? (= (* 2 (+ x y)) %)])))
See also: with-constraints, defconstrainedfn, and clojure.core.contracts.constraints</pre>
</div></div>
<h3><a name="ns"></a>ns</h3>
<p>The ns docstring could be improved f.ex. like this</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">The <span class="code-keyword">public</span> contracts programming functions and macros <span class="code-keyword">for</span> clojure.core.contracts.
Primary usage: defconstrainedfn or contract and with-constraints.
Use provide <span class="code-keyword">for</span> functions you don't control.</pre>
</div></div>
<h3><a name="Other"></a>Other</h3>
<p>There are other undocumented or too lightly documented fns/macros that would benefit<br/>
from improvements, f.ex.</p>
<ul>
<li>what does _ do?</li>
<li>provide would benefit from a (even brief) example</li>
<li>require-with-constraints - what is it, when to use?</li>
<li>in - an example would be nice</li>
<li>whitelist - the argument should be 'thing' not 'things' to be consistent with the docstring and the fact that it is a single map/set</li>
<li>an example of using implies, &lt;=&gt;, etc. would be nice - currently I don't really know when/why to use it (not mentioning how) [perhaps in the ns docstring, all this functions docstring having "... see the ns docstring")</li>
<li>why is defconstrainedfn in constraints.clj and not contracts.clj as the other main fns?<br/>
Why does provide use "kontracts" instead of "c" as with-constraints does? (The mismatch of "constraint" and "contract" - fn is with-constraints but takes contracts - is in itself confusing but that is another story.)</li>
<li>defconstrainedrecord has no doc</li>
</ul>
<p>I would be really happy if at least some of these improvements were applied. I believe it would help to spread contract programming more.</p>
<p>Thank you!</p>CCONTRACTS-6Add/improve docs of contract, clojure.core.contracts, etc.TaskMajorOpenUnresolvedFogusJakub HolydocumentationWed, 30 Apr 2014 07:45:31 -0500Wed, 30 Apr 2014 07:45:31 -050000Global Rank