<< Back to previous view

[CCONTRACTS-4] provide macro fails for multiple constraints Created: 28/Jan/14  Updated: 28/Jan/14

Status: Open
Project: core.contracts
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: joerupen Assignee: Fogus
Resolution: Unresolved Votes: 0
Labels: None
Environment:

clojure 1.5
core.contracts 0.5



 Description   

The following code shows 2 ways for defining a function with constraints.

=> it works as expected using the with-constraints macro
=> it fails on the second contract using the provide macro

(require '[clojure.core.contracts :as ccc])

;; because the provide macro alters the var-root, let's keep two separate identical functions for the test.

(defn qux [x] x)
(defn bar [x] x)

;; define 2 contracts
(def c1 (ccc/contract c1-cx "should be odd"
[x]
[(odd? x)]))

(def c2 (ccc/contract c2-cx "should have one digit"
[x]
[(= 1 (count (str x)))]))

;; using the provide macro => c1 is asserted, c2 never. When we swap around c2 c1, then c2 is asserted, c1 never
(ccc/provide [qux "qux" c1 c2])

;; on the other hand, using with-constraints works as expected.
(def qux-g
(ccc/with-constraints bar c1 c2))

(qux 2) ;; expected assertion "should be odd"
(qux 3) ;; expected 3
(qux 23) ;; expected assertion "only one digit", but we get 23

(qux-g 2) ;; should be odd
(qux-g 3) ;; OK
(qux-g 23) ;; should be positive






[CCONTRACTS-3] & for additional arguments does not seem to work when declaring a contract Created: 07/Sep/13  Updated: 07/Sep/13

Status: Open
Project: core.contracts
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Stephen Cagle Assignee: Fogus
Resolution: Unresolved Votes: 0
Labels: None


 Description   

user> (use '[clojure.core.contracts :only [contract]])
nil
user> (contract
silly
"Silly reporting for duty sir!"
[[a & b :as c]]
[])
CompilerException java.lang.RuntimeException: Unable to resolve symbol: & in this context, compiling:(NO_SOURCE_PATH:1:1)

the & in "a & b" is unresolved.






[CCONTRACTS-2] Does clojurescript support work for core.contracts? Created: 06/Sep/13  Updated: 06/Sep/13

Status: Open
Project: core.contracts
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Stephen Cagle Assignee: Fogus
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Clojurescript



 Description   

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.

In my behavior.clj I have

(ns ^:shared com.samedhi.contracts.app.behavior
(:require [clojure.string :as string]
[io.pedestal.app.messages :as msg]
[clojure.zip :as z])
(:use [clojure.core.contracts :only [contract with-constraints]]
[clojure.core.contracts.constraints :only [defconstrainedfn]]
[clojure.test :only [is]]))

which compiles into cljs as
...
goog.require('clojure.core.contracts.constraints');
goog.require('com.samedhi.quizry.app.quiz');
goog.require('clojure.core.contracts');
goog.require('clojure.test');
...

which throws a javascript exception at goog.require('clojure.core.contracts.constraints') when I look in the data-ui view, saying:

errorMessage: "goog.require could not find: clojure.core.contracts.constraints"
name: "clojure.core.contracts.constraints"

Is there some sort of special way I need to import things within clojurescript to use core.contracts?

BTW, I really appreciate core contracts, it is really neato. Thanks for you work.






[CCONTRACTS-1] Make defconstrainedrecord's predicate fast Created: 06/Jun/13  Updated: 28/Jun/13  Resolved: 28/Jun/13

Status: Resolved
Project: core.contracts
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Trivial
Reporter: Ambrose Bonnaire-Sergeant Assignee: Fogus
Resolution: Completed Votes: 0
Labels: None

Attachments: File fast-predicate2.diff     File fast-predicate.diff    

 Description   

Instead of using the slow `clojure.core/type`, use an inlining function calling `instance?`. I have not tested the performance, but it's probably much faster.



 Comments   
Comment by Ambrose Bonnaire-Sergeant [ 16/Jun/13 11:17 AM ]

These are the kinds of numbers I'm seeing between using type vs. instance? (220ms vs. 15ms).

Crude tests, but it should be obvious the inlining version is much faster.

user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 13.839681 msecs"
nil
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 19.862729 msecs"
nil
user=> (time (dotimes [_ 1e6] (instance? Integer 1)))
"Elapsed time: 15.176552 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 220.796493 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 220.6573 msecs"
nil
user=> (time (dotimes [_ 1e6] (= Integer (type 1))))
"Elapsed time: 224.051327 msecs"
nil
Comment by Ambrose Bonnaire-Sergeant [ 17/Jun/13 12:38 AM ]

Attached new patch: fast-predicate2.diff

Ensure instance? inlines. Needs to be put in a fn rather than definline.

There's a little benchmark. I noticed a speedup to 17ms for 1e6 iterations, from 185ms.

Comment by Fogus [ 28/Jun/13 8:11 AM ]

Applied on master. I will push a point-version out later today. Thanks.





Generated at Wed Apr 23 04:24:02 CDT 2014 using JIRA 4.4#649-r158309.