clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Oliver George 2020-08-06T02:10:14.055700Z

I keep wanting ::x/blah to expand to :current.namespace$x/blah when there's no x alias. It'd open up "private namespaces" for spec use.

Oliver George 2020-08-06T02:10:46.056500Z

My use case is CLJS function arg specs. I have many fns in a ns. They expect different things from a :db key passed in as context. (re-frame handlers)

Oliver George 2020-08-06T02:13:26.059400Z

With the proposed change I could do things like this

(ns app.events (:require [clojure.spec.alpha :as s]))
(defn event1 [{:keys [db]}] ...)
(defn event2 [{:keys [db]}] ...)
(s/fdef event1 :args (s/cat :ctx (s/keys :req-un [::event1/db]))
(s/def ::event1/db (s/keys :req-un [::ddb])))
(s/fdef event2 :args (s/cat :ctx (s/keys :req-un [::event2/db]))
(s/def ::event2/db (s/keys :req-un [::form])))

Oliver George 2020-08-06T02:18:12.062Z

Perhaps a macro would do the job so could add to replace keyword namespaces in a form

(rename-keyword-ns {*ns* :app.events$event1)
  (s/fdef event1 (s/cat :ctx (s/keys :req-un [::db]))
  (s/def ::db (s/keys :req-un [::ddb]))))

seancorfield 2020-08-06T02:45:32.063800Z

I suspect Spec 2 (a.k.a. what will eventually become just clojure.spec šŸ™‚ ) will help you here because you can define a schema will all the possible keys with their specs, all in one place -- and then you can select the specific keys that are required for each individual handler.

Oliver George 2020-08-06T04:29:32.067600Z

Good point. If/when that lands it'll be an improvement.

Oliver George 2020-08-06T04:29:33.067800Z

I guess it'd look something like this...

(ns app.events (:require [clojure.spec2 :as s]))
(defn event1 [{:keys [db]}] ...)
(defn event2 [{:keys [db]}] ...)
(s/def ::ctx (s/schema {:db ::db}))
(s/def ::db (s/schema {:ddb ::ddb :form ::form}))
(s/fdef event1 :args (s/cat :ctx (s/select ::ctx [:db {:db [:ddb]}]))
(s/fdef event2 :args (s/cat :ctx (s/select ::ctx [:db {:db [:form]}]))

Oliver George 2020-08-06T04:31:56.068600Z

(Guessing at the unqualified key bits)

arohner 2020-08-06T12:49:15.069200Z

spectrum is no where near working, and Iā€™m not sure whether I will have the time to finish it

johanatan 2020-08-06T17:50:29.070Z

hi, does clojure.spec.test.alpha/check run its test cases in sequence or in parallel ?

alexmiller 2020-08-06T18:00:15.070200Z

parallel via pmap

johanatan 2020-08-06T18:00:47.070700Z

any way to tell it to do sequential? because my code under test is already parallel and is kicking off a bunch of promises

johanatan 2020-08-06T18:01:08.071100Z

and the combination of the two is overwhelming the browser i'm afraid

alexmiller 2020-08-06T18:10:01.071300Z

not currently

johanatan 2020-08-06T18:14:21.071700Z

ok, no worries. i can just limit the num-tests to a small amount for now