clojure.spec

Can anyone explain me about the sh in clojure in order to execute the system command?

筅森魡賤 提交于 2021-02-05 12:24:55
问题 I'm using Mac OS. I want to execute a system command using (use '[clojure.java.shell :only [sh]]) , like in How to execute system commands?. I have read https://clojuredocs.org/clojure.java.shell/sh but wasn't able to understand things like how many parameters can be passed in one syntax, etc. In windows I have tried (sh "cmd" "/C" "dir") and it was working but in Mac OS, how do I execute the above syntax? Moreover I want to pass more parameters than just dir . For example, I want to execute

less verbose ways of spec'ing records and maps?

半世苍凉 提交于 2019-12-21 23:10:04
问题 Is there a less verbose way of making a spec for a map or a record than the way it is presented in the official spec guide? (defrecord Person [first-name last-name email phone]) (s/def ::first-name string?) (s/def ::last-name string?) (s/def ::email ::email-type) (s/def ::person (s/keys :req-un [::first-name ::last-name ::email] :opt-un [::phone])) ideally it would be nice if I could just write something like (defrecord Person [first-name last-name email phone]) (s/def ::person (s/keys :req

Where to put specs for Clojure.Spec?

…衆ロ難τιáo~ 提交于 2019-12-20 08:46:39
问题 So, I'm diving deeper and deeper into Clojure.Spec . One thing I stumbled upon is, where to put my specs . I see three options: Global Spec File In most examples, I found online, there is one big spec.clj file, that gets required in the main namespace. It has all the (s/def) and (s/fdef) for all the "data types" and functions. Pro: One file to rule them all Contra: This file can be big Single Responsibliy Principle violated? Specs in production namespaces You could put your (s/def) and (s

No such namespace: clojure.spec.alpha in clojurescript project setup

天涯浪子 提交于 2019-12-12 10:52:18
问题 I am trying to learn clojure.spec . While setting up a clojure project along boot build tool I am getting following error while requiring the clojure.spec.alpha. Compiling ClojureScript... • js/app.js No such namespace: clojure.spec.alpha, could not locate clojure/spec/alpha.cljs, clojure/spec/alpha.cljc, or Closure namespace "clojure.spec.alpha" in f ile src/cljs/flowparser/app.cljs Elapsed time: 0.141 sec My Boot Configuration is as follows: (def +version+ "0.0.1-SNAPSHOT") (def

Generating from recursive definitions with Clojure Spec

房东的猫 提交于 2019-12-10 14:04:19
问题 Let's consider a Clojure Spec regexp for hiccup syntax (require '[clojure.spec :as spec]) (spec/def ::hiccup (spec/cat :tag keyword? :attributes (spec/? map?) :content (spec/* (spec/or :terminal string? :element ::hiccup)))) which works splendidly (spec/conform ::hiccup [:div#app [:h5 {:id "loading-message"} "Connecting..."]]) ; => {:tag :div#app, :content [[:element {:tag :h5, :attributes {:id "loading-message"}, :content [[:terminal "Connecting..."]]}]]} until you try to generate some

How do I set up a clojureScript project to use specs and test the clojure.core functions at runtime?

こ雲淡風輕ζ 提交于 2019-12-10 10:22:11
问题 Clojure 1.9 introduced specs. Functions in the clojure.core library now have specs. How do I set up a clojurescript project to use specs and test the clojure.core functions at runtime? I used the libraries [org.clojure/test.check "0.10.0-alpha2"] and [org.clojure/spec.alpha "0.1.123"] to install specs and the command instrument . It worked to detect problems in functions that I wrote specs. But it didn't detect problems with clojure.core (for instance, map ). Maybe specs do not work with

How to check distinct id in spec/coll-of

泪湿孤枕 提交于 2019-12-08 02:29:21
问题 (s/def ::users (s/coll-of ::user :distinct true)) The spec above requires each user map to be distinct but How can I specify it to check for distinct :user/ids only The collection bellow shouldn't be allowed: [{:id 10 :name "Jessica"} {:id 10 :name "Erica"}] 回答1: (s/def ::id (s/int-in 0 40)) ; just for testing purposes (s/def ::name string?) (s/def ::user (s/and (s/keys :req-un [::id ::name]))) (s/def ::user-list (s/and (s/coll-of ::user :distinct true :into []) #(if (empty? %) true (apply

How to check distinct id in spec/coll-of

走远了吗. 提交于 2019-12-06 09:17:13
(s/def ::users (s/coll-of ::user :distinct true)) The spec above requires each user map to be distinct but How can I specify it to check for distinct :user/ids only The collection bellow shouldn't be allowed: [{:id 10 :name "Jessica"} {:id 10 :name "Erica"}] (s/def ::id (s/int-in 0 40)) ; just for testing purposes (s/def ::name string?) (s/def ::user (s/and (s/keys :req-un [::id ::name]))) (s/def ::user-list (s/and (s/coll-of ::user :distinct true :into []) #(if (empty? %) true (apply distinct? (mapv :id %))))) (deftest so-test (let [users [{:id 11 :name "Jessica"} {:id 11 :name "Erica"}]]

clojure.spec human readable shape?

时光怂恿深爱的人放手 提交于 2019-12-06 04:01:32
问题 With clojure.spec, is there a way to define a more “human-readable” spec for nested maps? The following doesn't read very well: (s/def ::my-domain-entity (s/keys :req-un [:a :b]) (s/def :a (s/keys :req-un [:c :d])) (s/def :b boolean?) (s/def :c number?) (s/def :d string?) Given that the shape of a conforming entity is something like {:a {:c 1 :d "hello"} :b false} My complaint is that it becomes hard(er) to read a spec if it has any sort of nested maps or any deep structure… because you are

less verbose ways of spec'ing records and maps?

不羁岁月 提交于 2019-12-04 19:09:58
Is there a less verbose way of making a spec for a map or a record than the way it is presented in the official spec guide? (defrecord Person [first-name last-name email phone]) (s/def ::first-name string?) (s/def ::last-name string?) (s/def ::email ::email-type) (s/def ::person (s/keys :req-un [::first-name ::last-name ::email] :opt-un [::phone])) ideally it would be nice if I could just write something like (defrecord Person [first-name last-name email phone]) (s/def ::person (s/keys :req-un [:first-name string? :last-name string? :email ::email-type] :opt-un [:phone])) It is Clojure team's