<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions in core.contracts</title>
<link>https://ask.clojure.org/index.php/questions/contrib-libs/core-contracts</link>
<description></description>
<item>
<title>Add/improve docs of contract, clojure.core.contracts, etc.</title>
<link>https://ask.clojure.org/index.php/707/add-improve-docs-of-contract-clojure-core-contracts-etc</link>
<description>Even though {{contract}} is a key thing in the library, it lacks a docstring.&lt;br /&gt;
The docstring of the ns could also have a few words pointing to the main functions&lt;br /&gt;
and how to use them.&lt;br /&gt;
&lt;br /&gt;
h3. contract&lt;br /&gt;
&lt;br /&gt;
For contract, st. like would be nice (excuse my poor understanding of the lib):&lt;br /&gt;
&lt;br /&gt;
Define a named and documented contract.&lt;br /&gt;
&lt;br /&gt;
constraints =&amp;gt; signature-constraint*&lt;br /&gt;
signature-constraint =&amp;gt; argument-vector constraint-vector&lt;br /&gt;
constraint-vector =&amp;gt; functions and expressions [=&amp;gt; functions and expressions]&lt;br /&gt;
&lt;br /&gt;
The functions are applied to the arguments, an expressions is executed as-is.&lt;br /&gt;
Constraint following `=&amp;gt;` are post-conditions and may use `%` to refer to the return value.&lt;br /&gt;
&lt;br /&gt;
Ex.:&lt;br /&gt;
&lt;br /&gt;
(contract doubler&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;quot;ensures doubling (sometimes)&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;[x] [number? =&amp;gt; integer?]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;[x y] [(every? number? [x y])&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;integer? (= (* 2 (+ x y)) %)])))&lt;br /&gt;
&lt;br /&gt;
See also: with-constraints, defconstrainedfn, and clojure.core.contracts.constraints&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
h3. ns&lt;br /&gt;
&lt;br /&gt;
The ns docstring could be improved f.ex. like this&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The public contracts programming functions and macros for clojure.core.contracts.&lt;br /&gt;
Primary usage: defconstrainedfn or contract and with-constraints.&lt;br /&gt;
Use provide for functions you don't control.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
h3. Other&lt;br /&gt;
&lt;br /&gt;
There are other undocumented or too lightly documented fns/macros that would benefit&lt;br /&gt;
from improvements, f.ex.&lt;br /&gt;
* what does _ do?&lt;br /&gt;
* provide would benefit from a (even brief) example&lt;br /&gt;
* require-with-constraints - what is it, when to use?&lt;br /&gt;
* in - an example would be nice&lt;br /&gt;
* whitelist - the argument should be 'thing' not 'things' to be consistent with the docstring and the fact that it is a single map/set&lt;br /&gt;
* an example of using implies, &amp;lt;=&amp;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 &amp;quot;... see the ns docstring&amp;quot;)&lt;br /&gt;
* why is defconstrainedfn in constraints.clj and not contracts.clj as the other main fns?&lt;br /&gt;
Why does provide use &amp;quot;kontracts&amp;quot; instead of &amp;quot;c&amp;quot; as with-constraints does? (The mismatch of &amp;quot;constraint&amp;quot; and &amp;quot;contract&amp;quot; - fn is with-constraints but takes contracts - is in itself confusing but that is another story.)&lt;br /&gt;
* defconstrainedrecord has no doc&lt;br /&gt;
&lt;br /&gt;
I would be really happy if at least some of these improvements were applied. I believe it would help to spread contract programming more.&lt;br /&gt;
&lt;br /&gt;
Thank you!</description>
<category>core.contracts</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/707/add-improve-docs-of-contract-clojure-core-contracts-etc</guid>
<pubDate>Wed, 30 Apr 2014 13:45:32 +0000</pubDate>
</item>
<item>
<title>Fix links in and display of documentation</title>
<link>https://ask.clojure.org/index.php/706/fix-links-in-and-display-of-documentation</link>
<description>&lt;p&gt;There is a number of problems with the way the documentation is made available and interlinked:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Currently most people likely arrive to &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/core.contracts&quot;&gt;https://github.com/clojure/core.contracts&lt;/a&gt; and read the README - but it does not point to the docs in {{./docs/}} =&amp;gt; add link to it there&lt;/li&gt;
&lt;li&gt;It is not clear how the docs are expected to be browsed; I suppose that the .org&lt;br&gt;
 files should be exported to                                                                                             *  } yet not all of them are. I also&lt;br&gt;
 suppose that the exported markdown files should be available under &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/core.contracts/wiki&quot;&gt;https://github.com/clojure/core.contracts/wiki&lt;/a&gt;, i.e. pushed to git@github.com:clojure/core.contracts.wiki.git&lt;/li&gt;
&lt;li&gt;Some of the problems: &lt;pre&gt;&lt;code&gt; *  the link &quot;return to documentation&quot; on e.g. &quot;with-constraints&quot; should point to /clojure/core.contracts/wiki, not /clojure/core.contracts/docs.html
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;if wiki is really exported, the main page should mention it is immutable&lt;/li&gt;
&lt;li&gt;links on the home page &lt;strong&gt;had&lt;/strong&gt; one more 'wiki' in them (fixed manually in the wiki - will be overriden by the next export)&lt;/li&gt;
&lt;li&gt;some links are broken, f.ex. (link: defconstrainedfn)(/clojure/core.contracts/wiki/defconstrainedfn) on f.ex. {{contract}}; (link: with-constraints)(/clojure/core.contracts/with-constraints/) (missing /wiki/), (link: defcontract)(/clojure/core.contracts/wiki/defcontract/)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It would certainly help the project if the documentation was easier to access and browse :-)&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;
</description>
<category>core.contracts</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/706/fix-links-in-and-display-of-documentation</guid>
<pubDate>Wed, 30 Apr 2014 12:37:14 +0000</pubDate>
</item>
<item>
<title>provide macro fails for multiple constraints</title>
<link>https://ask.clojure.org/index.php/708/provide-macro-fails-for-multiple-constraints</link>
<description>&lt;p&gt;The following code shows 2 ways for defining a function with constraints.&lt;/p&gt;
&lt;p&gt;=&amp;gt; it works as expected using the with-constraints macro&lt;br&gt;
=&amp;gt; it fails on the second contract using the provide macro&lt;/p&gt;
&lt;p&gt;(require '(link: clojure.core.contracts :as ccc))&lt;/p&gt;
&lt;p&gt;;; because the provide macro alters the var-root, let's keep two separate identical functions for the test.&lt;/p&gt;
&lt;p&gt;(defn qux (link: x) x)&lt;br&gt;
(defn bar (link: x) x)&lt;/p&gt;
&lt;p&gt;;; define 2 contracts&lt;br&gt;
(def c1 (ccc/contract c1-cx &quot;should be odd&quot;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;            (link: x) 
            (link: (odd? x))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(def c2 (ccc/contract c2-cx &quot;should have one digit&quot; &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;			(link: x)
            (link: (= 1 (count (str x))))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;;; using the provide macro =&amp;gt; c1 is asserted, c2 never. When we swap around c2 c1, then c2 is asserted, c1 never&lt;br&gt;
(ccc/provide (link: qux &quot;qux&quot;  c1 c2))&lt;/p&gt;
&lt;p&gt;;; on the other hand, using with-constraints works as expected.&lt;br&gt;
(def qux-g&lt;br&gt;
  (ccc/with-constraints bar c1 c2))&lt;/p&gt;
&lt;p&gt;(qux 2) ;; expected assertion &quot;should be odd&quot;&lt;br&gt;
(qux 3) ;; expected 3 &lt;br&gt;
(qux 23) ;; expected assertion &quot;only one digit&quot;, but we get 23&lt;/p&gt;
&lt;p&gt;(qux-g 2) ;; should be odd&lt;br&gt;
(qux-g 3) ;; OK&lt;br&gt;
(qux-g 23) ;; should be positive&lt;/p&gt;
</description>
<category>core.contracts</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/708/provide-macro-fails-for-multiple-constraints</guid>
<pubDate>Tue, 28 Jan 2014 20:04:47 +0000</pubDate>
</item>
<item>
<title>&amp; for additional arguments does not seem to work when declaring a contract</title>
<link>https://ask.clojure.org/index.php/705/additional-arguments-does-seem-work-when-declaring-contract</link>
<description>&lt;p&gt;user&amp;gt; (use '(link: clojure.core.contracts :only [contract)])&lt;br&gt;
nil&lt;br&gt;
user&amp;gt; (contract&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;   silly
   &quot;Silly reporting for duty sir!&quot;
   (link: [a &amp;amp; b :as c])
   (link: ))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;CompilerException java.lang.RuntimeException: Unable to resolve symbol: &amp;amp; in this context, compiling:(NO_SOURCE_PATH:1:1)&lt;/p&gt;
&lt;p&gt;the &amp;amp; in &quot;a &amp;amp; b&quot; is unresolved.&lt;/p&gt;
</description>
<category>core.contracts</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/705/additional-arguments-does-seem-work-when-declaring-contract</guid>
<pubDate>Sun, 08 Sep 2013 04:29:48 +0000</pubDate>
</item>
<item>
<title>Does clojurescript support work for core.contracts?</title>
<link>https://ask.clojure.org/index.php/704/does-clojurescript-support-work-for-core-contracts</link>
<description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;In my behavior.clj I have&lt;/p&gt;
&lt;p&gt;(ns ^:shared com.samedhi.contracts.app.behavior&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(:require (link: clojure.string :as string)
             (link: io.pedestal.app.messages :as msg)
             (link: clojure.zip :as z))
(:use (link: clojure.core.contracts :only [contract with-constraints)]
        (link: clojure.core.contracts.constraints :only [defconstrainedfn])
        (link: clojure.test :only [is])))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which compiles into cljs as &lt;br&gt;
...&lt;br&gt;
goog.require('clojure.core.contracts.constraints');&lt;br&gt;
goog.require('com.samedhi.quizry.app.quiz');&lt;br&gt;
goog.require('clojure.core.contracts');&lt;br&gt;
goog.require('clojure.test');&lt;br&gt;
...&lt;/p&gt;
&lt;p&gt;which throws a javascript exception at goog.require('clojure.core.contracts.constraints') when I look in the data-ui view, saying:&lt;/p&gt;
&lt;p&gt;errorMessage: &quot;goog.require could not find: clojure.core.contracts.constraints&quot;&lt;br&gt;
name: &quot;clojure.core.contracts.constraints&quot;&lt;/p&gt;
&lt;p&gt;Is there some sort of special way I need to import things within clojurescript to use core.contracts?&lt;/p&gt;
&lt;p&gt;BTW, I really appreciate core contracts, it is really neato. Thanks for you work.&lt;/p&gt;
</description>
<category>core.contracts</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/704/does-clojurescript-support-work-for-core-contracts</guid>
<pubDate>Fri, 06 Sep 2013 23:55:42 +0000</pubDate>
</item>
</channel>
</rss>